How to Use the Naneato M0 Microcontroller Board

Introduction

Our Naneato M0 microcontroller board is one of the smallest and still practical boards out there. The entire board is only 16.5mm (0.65″) long and 10.2mm (0.4″) wide. It is only just longer than the footprint of a DIP-8 component. It also has 2.54mm (0.1″) pitch pins so that it can fit in a breadboard and can be used with standard jumper wires. But don’t get fooled by its size and price. The Naneato M0 uses a powerful 32-bit ARM Cortex M0 STM32F042G, which runs at 48MHz, has 6KB of SRAM, and has 32KB of flash memory.

Features

The board includes a 3.3V regulator that can be used to power itself through the Micro-USB port or with a power supply up to 23V and output up to 500mA on the VCC pin. There are 3 analog/digital pins and 2 solely digital pins, all of which are PWM capable. Some of the pins also support I2C, UART, or SPI. The STM32F042G has built in USB functionality which works for uploading code through the USB port, and for acting as an HID device. Along with a reset and bootloader button for easier uploading. More of the STM32F042G’s features include:

  • 32KB of flash memory
  • 6KB of SRAM
  • 12 bit ADC
  • 48MHz
  • Native USB

Layout and Pinout

Underneath the Micro-USB port on the back of the board, there is silkscreen text that marks each of the pins for easy reference. The first 3 pins at the top right are for the regulator input, ground, and the 3.3V output. The rest of the pins on the board are GPIO pins, some of which are analog/digital, and some of which are solely digital.

On the top side of the board, there are two buttons marked “R” and “B” on the silkscreen. The “R” button is the reset button, and the “B” button is the bootloader button. The bootloader or “boot” button will always need to be used when uploading through the USB port.

  • Power Input can be used with an external power source like a battery or a power supply. You can connect up to 23V to this pin, which will be regulated down to 3.3V through the voltage regulator. This pin is also connected to the 5V from the USB port, so both power sources shouldn’t be connected at the same time. The regulator has over-current and thermal protection, and can output up to 500mA to the VCC pin. When powering the board through the Vin pin, it is better to use a lower voltage closer to the minimum of 3.7V, as these types of linear regulators turn the extra power into heat. If you are using 23V, you will likely not be able to draw 500mA before the regulator overheats.
  • Power Ground is the common ground bus between everything on the board. If you are powering the board or connecting a device to it, you will likely need to connect this pin.
  • 3.3V Output is connected to the 3.3V power bus on the whole board and can be used to power small devices like small motors, sensors, and LEDs. It is also the output from the voltage regulator. The VCC pin can also be used as a power input ONLY if your supply is a regulated 3.3V. You can pull up to 500mA from this pin when powering through the USB port or the Vin pin.
  • GPIO Pins Are the input and output pins on the board. There are 5 of them which can all be used as either inputs or outputs. All of the pins can output a PWM signal, for example using the analogWrite(); function in the Arduino IDE. All of the pins except 0 and 1 can work as analog inputs which means you can read an analog signal from them, not just a digital signal. These pins are labeled in the pinout diagram below

Below is the pinout diagram of the board. Key things to look out for are where the analog pins are, where the solely digital pins are, where the PWM pins are, and where peripheral pins like SDA and SCL are.

Each GPIO pin can only supply up to 25mA safely, which means you cannot run high power devices (like any motor) directly off of them. But for example, connecting a small LED to a pin directly is okay. There is also a 80mA max output for all of the pins combined, so as an example a limit could be 20mA from 4 I/O pins at the same time. If you need to control high power devices, you can do so by using a transistor to supply the device with another power source like the 3.3V from the VCC pin, or a higher power external power supply.

Because this board uses 3.3V logic, connecting 5V devices to the I/O pins is not always safe. In case you need the ability to have 5V outputs or have the rest of the pins work as 5V digital inputs, you can use a bidirectional logic level converter like this one to convert those signals from 3.3V to 5V and back.

If just the USB port is connected to a computer, you can use the Vin pin as a 5V reference along with the 3.3V from the VCC pin for hooking up logic level converters. Digital pins 2 and 3 are the only pins that can natively support 5V inputs, but they cannot have internal pull-up or pull-down resistors enabled if doing so.

Setup For Arduino IDE

To program the Naneato M0 in the Arduino IDE, we will need to install a boards package for it and the STM32 Cube Programmer software. Also make sure you have the latest version of the Arduino IDE installed. If you don’t have the Arduino IDE already, you can get it here.

You can install the latest STM32 Cube Programmer software here. It is a tool for programming STM32 products, and you can also use it on its own. Make sure you download it to the default directory, as you wont be able to upload code using the Arduino IDE otherwise.

To install the boards package, go to File > Preferences then next to “Additional boards manager URL’s” enter this: https://circuitneato.github.io/package_circuitneatoboards_index.json (making sure it is on a new line if necessary). This will download the needed board definitions in the Arduino IDE.

Now go to Tools > Board > Boards Manager or click the board manager button found at the left side of the IDE screen. Then search for “Circuitneato ARM Boards” and click the install button for “Circuitneato ARM Boards” by Circuitneato Electronics.

After it finishes installing, go into Tools > Board > Circuitneato ARM Boards and select the Naneato M0 option.

The Upload Method option can be left as default (STM32CubeProgrammer (DFU)), and the USB Support option can be kept set as None, or set to HID to be able to use the board as a keyboard or mouse.

Programming Within the Arduino IDE

You can write code for the Naneato M0 like you would for any other Arduino board. For example, you can use digitalWrite(); and digitalRead(); to write either a high or low signal to any of the pins, or read a high/low signal from them.

You can also use analogWrite(); and analogRead(); to output a PWM signal on the PWM capable pins, or read an analog signal on the analog pins.

pinMode(); can be used to set a pin as an output, input, or an input with its internal pull-up or pull-down resistors enabled pinMode(0, INPUT_PULLUP); or pinMode(0, INPUT_PULLDOWN);. And because the microcontroller has native USB, you can also use Arduino libraries like Keyboard and Mouse with it.

Below is a simple blink sketch that will drive pin 0 high and low every second.

void setup() {
  pinMode(0, OUTPUT);    // set pin 0 as an output
}

void loop() {
  digitalWrite(0, HIGH); // drive pin 0 high (3.3V)
  delay(1000);
  digitalWrite(0, LOW);  // drive pin 0 low (0V)
  delay(1000);
}

Uploading

To upload this code to the Naneato M0, start by connecting a Micro-USB cable from the board to your computer. Then double check the board settings are still the same from what we set up at the start of this tutorial. Now hold down the bootloader button on the board, press the reset button for a short period, and then let go of the bootloader button. This sets the microcontroller into bootloader mode, and code can now be uploaded.

The board wont show as connected in the Arduino IDE like other classic Arduino boards do, which is okay. After pressing the upload button, compiling may take around 20 seconds, and after that the code should upload successfully. You will need to put the device in bootloader mode every time before you upload.

If you get an error like this: STM32_Programmer.sh/STM32_Programmer_CLI.exe not found. make sure STM32CubeProgrammer is installed, and if it is, uninstall it and install it again, making sure to set it up with the default settings and file locations. More information can be found here.

Resources


More Tutorials

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *