Wednesday, 24 July 2024

Code Club Showcase Ideas

  • Use microbits for data gathering (well-known and easy) and ESP8266 for wifi to hub
    • microbit<->ESP8266 via serial port(s)
      • This is relatively simple
    • microbit<->ESP8266 via I2C!! An interesting idea 
      • Uses Wire() library on ESP, I2C on microbit
  • Experimenting with ESP32 microPython Bluetooth
    • Using ChatGPT (!) generated code - it refers to ble_advertising module
    • Didn't get that to work yet, in fact it gave wrong answers for the ESP32 code and the microbit code just wouldn't run
I found kaspersMicrobit, which allows my MBA to connect using BLE to a microbit running the UART service, and sending regular text strings. The maximum length of text appears to be 20 bytes. It's nice to get a success, but it would need to be ported to MicroPython, ESP32 version!

I have also tried using aioble, the MicroPython library to talk to the microbit. So far, I've managed to receive the integer from the temperature service. The UART service seems to require use of the notify and then some kind of transfer/read operation to get the text - there is no READ operation flag on it, only NOTIFY. I haven't worked out haw to do that with aioble yet. 

The V1 microbit runs out of memory pretty fast, I'm not sure how much you could do with it in respect of actually connecting sensors and so on.

Saturday, 4 May 2024

Minecraft and ??

 The Code Club is looking for some engaging project material, so we're going to start collecting environmental data (microbits, esp8266, DS18B20, SHT3X, CO2 sensors), behaviour survey data (Google Forms, Sheets) and other data (Openweather.org, the RPi weather project when it works), and hopefully collating it all in an internal web site. 

Part of this will be about the school's environment, in-room data being collected and hopefully displayed and analysed. Maybe we can do something about the litter problem too!

Some of the CC members are keen Minecraft players, and I wondered if it would be possible to get Minecraft involved in displaying data. It turns out that Minecraft is a Minefield, with two different game implementations (Java - Windows/OSX/Linux; Bedrock - Windows/XBox/PSx/iOS), and loads of concepts to get one's head around. Of course, MC is a client/server architecture multiplayer game, so maybe the client isn't important, only the server, which we can get copies of. However, note that the server provided at that link is only compatible with Java Edition.

The Fandom Minecraft wiki has lots of useful analysis of the MC architecture and so on. It turns out that the desktop/tablet/console "client" actually has both client and server components:

  • Client component handles movement, display etc., as you'd expect, as well as various server functions that operate locally to reduce the required network bandwidth, and which sync with the server when they can
  • A server instance, hosted on the local device, which provides the local worlds, and which behaves like the actual server
  • Remote server for multiplayer interaction, which is hosted on another computer
I've actually paid money (£35!) for the full Mac OSX version, to try some of this out. I note that the single player game allows its server to be opened to other LAN-originated players, so you could do multiplayer from a desktop "client" server if you wanted to try something.

To be continued...

 

Sunday, 11 February 2024

Microbits and external temperature/humidity sensors

 Microbits come with a built-in temperature sensor, but sadly it's

  • built into the chip, so gets affected by the chip heat
  • built into the board, so hard to measure stuff other than by dropping your microbit into the water you're trying to measure the temperature of (for example!)
There are lots of temp/humidity sensors, but I happened to have these digital sensors lying around:
  • DS18B20 - the model in a can, so relatively waterproof and on a 1m lead
  • SHT30 - this is a T/RH measuring chip, which I have on a Wemos-style PCB, convenient for normal people to use
Also, at the Science Oxford Creative Computing session this weekend I bumped into a lady who is fundraising to buy a bunch of data sensors for her primary school - looking for ~£700 to buy maybe 5!! That seems like madness, as they already have a bunch of microbits and do coding on them. Why not look at combining the two resources?

DS18B20

This package uses the Dallas Semi OneWire protocol, which is basically serial data in a specific format. 

This was by far the easiest, as there is actually an official Makecode Extension for this. In the Makecode Editor, use the Extensions menu item, and search for "dstemp". This brings up a very simple Block code extension which accesses the DS18B20 that is connected to the specified pin.

I used a microbit extension board and breadboard to connect the DS18B20, along with a 4K7 pull-up resistor (connected between DS18B20 Data wire and 3V pin). It worked instantly! Total result. Of course, the microbit output can easily be sent to the Chrome browser Makecode console where it can be graphed and downloaded as a CSV. Fab.

SHT30

This chip uses 12C, a bus-based protocol which is already used in the microbit for the Accelerometer and Compass, on pins 19 & 20. So the SHT30 can be added to the bus with no problem. 

Making this work was a bit more complicated, probably because 
  • I didn't look hard enough
  • The use of separate modules in Mu/Mbit MicroPython wasn't obvious 
I ended up finding some MicroPython which needed a lot of adaptation, but there is a much simpler approach here, which if I'd found earlier I'd have borrowed immediately.

Again, the microbit extender board allowed me to connect the +3V, Gnd, pin 19 and 20 (default SCL/SDA pins). I'd already mounted pins on the Wemos board so I could plug it into the breadboard. 

My code, like that referred to above, ends up as 2 files:
  • main.py, which imports SHT30.py as a module (it's a class)
  • SHT30.py
The tricky bit was realising I had to load the SHT30.py file into the microbit file system using the Files menu item in Mu. Once I did that, it started to work. And of course it provides T and RH, which will be great for a primary school doing data collection and analysis.