Developing on a NodeMCU board with Micro Python

I have a problem collecting rubbish and recycling saturation data. I’ve tried developing on existing ESRI apps to collect data and store it in the cloud. Its failed every time. These approaches failed because no one likes doing data entry on a phone or tablet, the guys who drive the truck. A clipboard is still more reliable than a smartphone but that cannot collect the street or time stamp. But who doesn’t like hitting an old arcade button right? I’m trying to develop a data collection method that’s manual but digital, easy and cheap.

NodeMCU vs Arduino

I’m developing a data entry platform using old arcade buttons I have lying around and originally an Arduino Uno. A friend recommended that I replace the Arduino with a NodeMCU board. It comes with a built in WiFi module and you can completely reconfigure the os of the board to run using MicroPython, which is totally awesome. It’s also a great leap forward in the sense that you can have boards printed to a custom level, where you can begin to appreciate new aspects of circuit design.

Failed attempt to proceed using microPython OS

I’ve flashed micropython as the os, connected to the nodeMCU board using PuTTY and am showing what’s on the board in the screenshot below. By running os.listdir(), which is python for the linux ‘ls’ command you can see we have 3 files.

When the board gets powered up or wakes up from a sleep cycle it executes and then This is really helpful because we can just modify these python files to execute the code we want to run.

Modifying the file

Ordinarily would have nothing in it, so when the board executes the script…. Nothing happens. With a few little modifications the board turns on, and executes the following code:

In essence when the board is reset or a button is pushed, technically the same thing in this case, then it opens up a text file called ‘data.txt’, saves the current value as a variable and then increment it by one. I’ll improve this later but as proof of concept it works.

Managing the device with ampy

Adafruit have released a 3rd party library which makes managing files on the system easier called ampy; it makes interacting with files on the system nice and easy. It’s a command line tool which let you do things like pull and push data from the chip as well as manage the file system.

In practice a simple little command like this will get us what we need.

ampy –port COM5 -b 115200 get

Attaching the BIG red Button!

The board alone deals with the WiFi, os, clock etc but I really want to attach some external hardware so that a driver can hit the button and increment the values in data.txt

I’ve been testing the code by hitting the reset button. When the board resets it runs the code in and For the real thing I want to attach some means of easy data entry, so an awesome arcade button. The NodeMCU board will reset if you connect the RST pin, which is reserved on this board for a wake command. I’ve wired up the big red button so that it complete the circuit and resets the board when pressed, this runs the code.


Now that the button works we need to grab time. Unfortunately this is where things really fell apart. The NodeMCU does not have an RTC (real time clock) module built in. So we needed to connect up another piece of hardware to do timekeeping. This was really tricky in python because there were very few libraries written to handle low level code interaction with other pieces of hardware.

You can connect a module to handle time interaction, but that’s quite specialized when you could just interact with a GPS module. No libraries available 😦

This is why people usually do this type of development in lower level languages such as C++. I;m writing this in retrospect and have now completed this same project using C++. Stay tuned, details to come.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: