Hacking with a NodeMCU

Today I am hacking on a node MCU.

They look something like this:

I am trying to program them with the Arduino IDE because arduino is stupid easy to use.  Interestingly to bootstrap the NodeMCU to the arduino environment, instead of loading an instruction environment first, then loading code – as you do when you use other environments to program the node.  The arduino environment deletes everything on the node every time you want to write code, and rewrites the whole lot.  This is pretty awesome and probably saved someone from having to write some kind of translation code to make this guy do what that guy says.  As a consequence though; each upload takes around 20-30 seconds.  Even if it’s blink.

(this is blink:)

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

It’s pretty simple.  Anyways; I am not sure what will happen for longer programs, I assume they will just take the same amount of time, or be a negligible difference in time for any arbitrary sized program.

The thing that had me stuck today is – as you can see in the picture above, all the pins are numbered D0, D1, D2, but also some of them are reused for other functions.  Which means if I want to use them to turn on an LED I block whatever else was planning to use that GPIO.  When I got these chips I felt like they had more pins.  With more hacktyhack I will probably figure out which ones are important and which ones are not.

Another thing: in arduino pins are numbered (0,1,2,3,4), nowhere in the node/arduino help documentation does it mention but using the arduino environment if you tell it you want to use something on pin (D0) it will be just as happy as if you tell it you want to do something on pin (16) (as GPIO16 in the picture).  Well – there goes an hour of hacking at how to address a pin.

I can tell I am rusty because the problems I am having are basic ones; It’s not that I don’t know how to code things (I don’t but that’s not my problem yet) it’s that I don’t know what certain codes do, or what codes are needed.  For example, “Serial.begin(115200);” before you print anything to the console on the computer that you are plugged into, you need to have this line present.  I spent a good 10-15 mins without that line in a script before I checked an earlier script that was working to figure out what was different.  If I was a lot more used to this I would either:

  1. notice the missing line without having to actually check elsewhere
  2. immediately on having a problem drop down to a 3 line script (3 lines: start, do this, stop) to test the behaviour of the code.
  3. instantly go to check elsewhere on having a problem where I know somewhere else has solved it.

These things are what “experience” or “skill” is.  I wonder if there is a way to pre-train this skill without ever having encountered the challenge.  Of course if tomorrow only holds challenges I have seen before it will be easy to overcome them but tomorrow might hold a challenge I have never seen before.  And I know that now.  How can I be more prepared for the unknown…


Meta: this took me 20mins to write.

This entry was posted in electronics and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply