This project appeared in Make: Vol. 91. Subscribe for more maker projects and articles!

Want to build electronic gadgets fast and learn programming too? With the Oxocard Connect mini computer and cartridges, you can easily try out your own ideas, build prototypes for projects, or just play with ready-made gadgets and learn to code in a playful way. Together with our Innovators Kit you can take your first steps into the world of electronic components and learn how to combine them with a microcontroller to make all kinds of smart projects.

In this short project we’ll introduce you to programming the Oxocard Connect using the scripting language NanoPy and a full-fledged, browser-based programming platform (IDE) to quickly build an IoT thermostat with alarm and servomotor. You’ll connect the temperature sensor, alarm buzzer, and servo on a mini breadboard cartridge that plugs right into the Oxocard Connect’s expansion port, no soldering necessary!

About Oxocard Connect

The Oxocard Connect (Make: Edition) can be recognized by the Makey on the back (and also on the boot screen).

The Oxocard Connect is a mini computer with a display (240×240 pixels), joystick, USB-C connection, network functions, and an expansion port where you can plug in ready-made cartridges or circuits of your own. The core of the Oxocard is the popular ESP32 microcontroller with 2MB PSRAM, 8MB Flash, Wi-Fi, and Bluetooth. The NanoPy language, based on MicroPython, is super easy to learn.

Thanks to the built-in Wi-Fi, and functions for HTTP and MQTT in NanoPy, you can not only run your projects locally but also send and collect data via the internet, to use your Oxocard for smart home projects or all kinds of IoT/cloud integrations.

Use it

Using Oxocard right out of the box is easy — no software installation, no typing out code listings and troubleshooting them! Instead you can start using the cartridges right away with the built-in examples, and then experiment with the code as you wish. “Use, Modify, Create” is Oxocard’s approach that quickly leads to initial successes and makes you want more. Sure, Oxocard and NanoPy together form a “learning system” — but it’s one that’s really fun and encourages curiosity.

Photo by Daniel Bachfeld

In the programming environment there’s a tutorial for each example project. These examples build on each other, and explain the special features of the NanoPy script. There’s also a command reference you can search.

NanoPy is based on the commands and structure of MicroPython, but its graphics functions are based on the Processing language, which is popular with beginners (and familiar to many makers from Arduino). This allows you to conjure up graphics on the display with just a few instructions. In the simplest example, just two commands:

drawRectangle(100, 100, 20, 20)update()

are sufficient to display on the Oxocard a rectangle at position x=100, y=100 and edge length 20.

The NanoPy command set also includes functions for 3D graphics.

Modify it

The Oxocard comes with a pre-installed operating system that connects via Wi-Fi to the browser-based IDE on nanopy.io and interprets the scripts. So you’re programming via Wi-Fi instead of USB like Arduino; but if you want, you can still program your Oxocard using a cable. This system works with Chrome and Edge, not Firefox-based browsers.

The NanoPy editor is also offered for download on GitHub so you can install it locally, but you’ll still need to go online for convenience functions such as reference, tutorials, and documentation.

In the online IDE you can try out examples, study tutorials and assembly instructions, and look up commands in the documentation.

At the push of a button, the IDE sends one of the many example programs to the Oxocard, which starts it locally on the ESP32. The Oxocard in turn sends data back to the IDE via Wi-Fi when the script is running, such as the output of the print command, which can be displayed using the Terminal window — practical when troubleshooting your own programs or modified examples.

In the IDE, values in the script or program can be modified during runtime using graphical sliders, and the effects on the Oxocard can be observed without having to go through the tedious process of recompiling and uploading like with Arduino!

There’s also a debugging function that allows you to run your scripts line by line and observe what values the variables take.

Why NanoPy?

Makers familiar with Python on computers, or MicroPython and CircuitPython on microcontrollers, will feel right at home learning NanoPy, but it’s fundamentally different underneath. NanoPy creator Thomas Garaio explains:

“NanoPy is an entry level scripting language. It’s made to look as similar to Python as possible, with “syntactic sugar,” but it’s not Python — it’s not dynamically typed, it’s statically typed, so you don’t need drivers or libraries, you just connect to the internet. So it’s easy to use but it’s also fast operationally!”

Learn more at nanopy.io

Create with it

With the debugger you can examine your program at runtime and check the contents of the variables.

By experimenting, you quickly get a feeling for the different commands and how they work. The self-explanatory function names also help with this. The many script examples can be easily combined, and there’s a separate section in the editor for your own scripts with the option to save them on the Oxocard. You can then call them up in the Start menu under My Scripts.

A sprite editor is available for graphics up to 24×24 pixels.

The integrated sprite editor is also practical — you can draw up to 24×24 sprites with pixel precision and transfer them to your program as an array with a click. In combination with the joystick, you can create games and graphic applications.

Plug-in cartridges

The Oxocard Connect can be connected to additional hardware via its expansion port, which opens up huge potential. In addition to cartridges with sound synthesizers, air quality sensors, and an LED pixel matrix, there’s the breadboard cartridge for electronics experiments. It’s even got LEDs on each I/O pin!

Bundled with around 30 electronic components, jumper wires, and of course the Oxocard Connect, Make: magazine offers this as the Oxocard Innovators Kit — Make: Edition. The kit includes a temperature-dependent resistor (NTC) for temperature measurements, a light-dependent resistor (LDR) for measuring brightness, a PIR sensor as a motion detector, as well as a piezo buzzer, servomotor, and various LEDs, buttons, and resistors. You can build all sorts of things with it.

Cartridges for the Oxocard Connect include the Breadboard, PixelMatrix, and Synthesizer shown here, plus Air cartridge with three gas sensors, ToF with 8×8 distance sensor, Veroboard, and more.

As an example, let’s build a smart thermostat: It should show the current temperature on the display, move a servo accordingly, sound an alarm when values exceed 30°C (86°F), and also send the temperature to your Wi-Fi network via an MQTT message.

The online IDE contains a tutorial with code, circuit diagrams, and construction suggestions for each electronic component, and for MQTT, so it’s easy to build up this project step by step!

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Build an IoT Thermostat

The circuit schematic shown in the online tutorials helps you wire the simple components.

First we’ll build the thermometer with the NTC thermistor. This temperature-dependent resistor, together with a 2.2kΩ resistor, creates a voltage divider we can measure with the Oxocard’s analog-digital converter (ADC) via pin IN06 on the breadboard cartridge. From this voltage, we can calculate the temperature using the characteristic values for our NTC. Our program is essentially:

while true: clear()
    adcValue = readADC(IN06, 100)
    T = calculateTfromA(adcValue)
    drawText(10,90, "T = " + T + "°C")
    update()
    delay(1000)

In an endless loop, the program clears the display with clear(), then reads the voltage value from the ADC. We see the first parameter of this function is the pin name, but what’s the second? In the NanoPy IDE, enter “readADC” in the search box to learn what the function does: “Reads the analog value … several times (nSamples) and calculates an average value.” Okay, 100 samples! This averaging function is used to filter noisy or fluctuating measurements.

We calculate the temperature T using our NTC’s conversion formulas, represented here by the dummy function calculatedTfromA(). With drawText() we write the value T to the x-y coordinates 10 and 90 and append the °C unit as a text string. However, only the update() command actually draws on the display. All text, figures, and pixels of the draw commands are first drawn internally in memory. Finally, delay() waits 1,000ms (1 second) before the loop is run through again. Click the Run Code button to send the program to the Oxocard Connect, and the current temperature in °C appears on the display.

Make it move

If you’re less familiar with circuit schematics, you can follow the assembly instruction diagrams à la Fritzing.

Measuring temperatures is, along with making LEDs blink, a favorite first project for makers — but it’s a bit boring. Let’s make it do something!

If you add a servomotor, you can physically react to the measured temperature, for example by moving a valve or knob, or the slats of a window blind.

Three lines are needed to control the servo:

setPWMFrequency(50)
dutyCycle = map(A, 90, -90, 102, 512)
writePWM(IO01, dutyCycle)

The first command sets the PWM frequency to the usual 50Hz for analog servos. The dutyCycle variable controls the servo angle, using a map() function to calculate the correct pulse width ratio, from 102 for 90 degrees to 512 for –90 degrees. (These values are derived from the Oxocard’s internal PWM frequency generation. Fortunately, everything’s already specified for you!)

Pass the result to our output pin IO01 using writePWM() and the servo is now set up. However, in order to move the servo linearly to the temperature, an additional call to map() is required, before the map() we just explained:

A = map(T, 40, 10, -90, 90)
dutyCycle = map(A, 90, -90, 102, 512)

This allows us to map our expected indoor temperatures of a maximum 40°C (104°F) to one full swing of the servo and a minimum 10°C (50°F) to the opposite swing. At 25°C (77°F) the servo should be approximately in the middle. 

Wired up: Our simple digital thermostat with alarm and servomotor.

Alarm and remote control

It would be nice to have an alarm sound when it gets too warm, for example above 30°C (86°F). Connect the piezo buzzer to pin IO02, and control it with a pulse width signal with a ratio of 50%:

if T > 30
    writePWM(IO02,4096/2)
else writePWM(IO02, 0)

We’ve already set the Oxocard’s PWM frequency to 50Hz for the servo, so we’ll have to use 50Hz again. As soon as the temperature falls below 30°C, the buzzer stops sounding.

It would be really nice to be able to control the temperature remotely, for example by having the Oxocard send the values via MQTT. Here too, the documentation will help you with a short introduction and a code example. You can publish the temperature via your Wi-Fi network like this:

uri = “mqtt://ip-address”
connectMQTT(uri, username, password)
publishMQTT(“Temperature”, T)

The two commands connectMQTT() and publishMQTT() are basically sufficient to connect to an MQTT server and send your own values via the Temperature topic.

Finally, we save the script on the EEPROM of the breadboard cartridge and configure the autostart. Now the Oxocard will execute our program as soon as the cartridge is inserted.

This is the finished script for the thermostat; you can download the script from our partners at Make: Germany here.

Conclusion

More to come!

Use, Modify, Create! That’s exactly the approach we used to build our own smart gadget with the Innovators Kit and, based on the existing examples, got it up and running quickly.

Make: is now developing supplemental materials around the Make: Edition Innovators Kit, and we’ll be using the Oxocard Connect in future projects in the magazine, so please send us your ideas for projects — and cartridges! 

Photos and screenshots by Daniel Bachfeld. This project appeared in Make: Vol. 91. Subscribe for more maker projects and articles!