Here’s a really easy demonstration of how you can control outputs on the NodeMCU with a simple web interface. The NodeMCU runs as a simple web server, writing a control panel interface directly as HTML.
The circuit is very simple, just four LEDs with resistors wired to outputs of the NodeMCU.
Here’s the wiring I used, which matches the code.
yellow – D1 = GPIO5
green – D2 = GPIO4
blue – D3 = GPIO0
red – D7 = GPIO13
In Arduino code, GPIO numbers map to Arduino digital outputs, so to turn on yellow LED use digitalWrite(5, HIGH)
How much do you have to spend on a robot for the classroom? There is a profusion of expensive, shiny toys on the market being promoted for STEM education, but this isn’t the only way to do robotics.
Here’s my prototype bare-bones robot. There’s nothing really new here, it’s just a couple of motors, a motor controller and an Arduino Nano board. It’s just to show how the most basic robot could be built as a starting point for my students to start thinking about their designs. There’s less than $20 worth of parts (if you buy directly from China, and order in bulk).
In this form it doesn’t do much, but the idea is that students will use the basic design as a platform on which to create their own unique projects. They have to think about what to use for a chassis, how to control it (IR, Bluetooth, WiFi, RF?), to put LEDs on it, sensors and so on.
Realised I have not written any updates here for half the year, it has been a busy time. I’m now teaching the Robotics/Electronics subject but getting students up to speed with theory has cut into real hands-on time.
I also received a grant so there are resources stashed away for when I have time to unpack and set up, but our new workspace is not ready yet.
Toys to play with include:
a laser cutter
3D printer (finally out of the box and doing some tests)
Arduino kits (these have been used by some of my more motivated kids)
micro:bits (got a bit of use already)
a weather station that needs to be installed, then we can use it to collect lots of data
Summer holidays in Australia and it has been a real scorcher of a week. As I need to get some preparation for the school year happening I am still playing with IoT here, even if it’s a little bit harder working away from home.
I’ve been playing with NodeMCU a bit more, because it has the obvious benefit of built-in WiFi, so once configured it just needs power and a network connection and you have data logging.
As noted in my previous post, Xively is no longer providing free hosting, so I need to find other options. A bit of hacking and some examplesonline and I have temperature logging being pushed to ThingSpeak. I’ve put the board outside plugged into a USB phone charger and am using a phone hotspot to provide internet connectivity. Proof-of-concept done!
With a bit of ingenuity and a lot of trial and error there are ways of making this IoT work without having to sign up for commercial services. Since I am doing this for hobbyist/education purposes I can’t really justify paying for business services.
Being the silly season, time was limited to get a new service onboard, although I did spend some time with ThingSpeak it didn’t go smoothly, so I would have to say that Xively do have a very good platform because it was so easy to get up and running in the first place. So at the moment the weather station isn’t logging to the web, and will need some more work done before it does.
The Xively feed started on Mar 14, 2014, so it has been logging data for almost four years. That was my first real IoT experiment so I’m pleased with that! It was interesting to be able to check the weather at home when we were on holidays, and you could even work out who had been working in the study by the changing light levels.
OK, HomeAssistant runs on RaspberryPi, but the RPi only has digital in/out, but what if I want to read analog values from sensors? One solution appears to be to use an Arduino, since this is the sort of thing they do well. However, finding details of how to do this seems a bit sketchy. I could use I2C, but that seems a bit tricky. I did read that I can use USB, which is convenient because that will also give me power for the Arduino. To use an Arduino as an add-on board for the RPi, I had read about something called Firmata, which loads as a sketch running on the Arduino. This is easy at the Arduino end, as it is just one of the examples pre-installed, upload and it’s ready to go.
I set up the configuration in HomeAssistant and immediately got a whole heap of errors, mostly referring to needing PyMata 2.14. Now PyMata is a client library that allows Python to control the Arduino. Obviously not part of the standard RPi/Hassbian image. After a bit of messing around here’s what I managed to do:
Plug the Arduino into your computer, load up the IDE and upload the StandardFirmata sketch (found in the Examples submenu)
Plug the Arduino into a USB port on the RPi. Log into the RPi using SSH
At the command line, run:
sudo pip3 install pymata
If you download the examples from the GitHub repository, you should be able to call the blink sketch to verify that all is working. It should flash the LED 10 times, and you should see the process running in your terminal session counting down. (Note that my UNO clone is connected at ‘/dev/ttyACM0’, so the script works as is.
Add the following entries to your configuration.yaml script and save it:
The LED should show up as another switch in your dashboard, and turning it on should light the pin 13 LED on the Arduino
Note that it appears you can only read analog input pins, and switch digital output pins through this interface. No PWM, and I suppose if you need to read digital inputs then you can do that directly on the RPi.
Thought it was time to step up the home automation effort, so a mention of HomeAssistant on a blog had me interested. So now the RaspberryPi is running some new software and I’ve been tinkering with this seeing what it can do. There’s not too many things in the house that are ‘smart’, but I can turn the TV off and control a WeMo switch. Much of the built-in functionality is impressive, so triggers for sunset or time let one test how it works. Integration with my phone also lets it track location and use geofencing for triggers also.
I’d be interested to see what can be done once I can integrate with other systems in the house, such as the alarm system, thermostat or pool controllers. Being open-source and open, there’s plenty of scope to ‘roll-your-own’ to meet individual needs.
Here’s a useful article on using the Hass.io version of HomeAssistant. Worth a look.
It’s interesting how things have come full circle. As a teenager, I used to buy Australian-published electronics magazines each month, and tinkered with making some projects. At that time, we had Electronics Today International, or ETI, and Electronics Australia. Early in the 90s ETI disappeared, and EA hung around a while longer. At some time some of the former EA staff set up a new magazine, Silicon Chip, which I have looked at from time to time.
Suddenly people are making things with electronics again, but the focus has shifted from analog circuitry to computer technology, and now that we have affordable programmable devices the hobby market is born again.I was quite excited to discover a new magazine launching in Australia, called Diyode. First new electronics magazine in the country for almost 30 years. I’ve subscribed, in print as well as digital, and the first issue arrived yesterday, a few days ahead of the newsstand launch. Good thing it’s school holidays and I’ll have some time to read it. Looks good, like some of the better UK magazines with full colour page spreads and some good practical articles.