Arduino Framework Blink Tests With SiPEED Maixduino

by Trevor Lee in Circuits > Arduino

294 Views, 0 Favorites, 0 Comments

Arduino Framework Blink Tests With SiPEED Maixduino

poster_small.png

In this post, I will show 3 Arduino framework blink tests with SiPEED Maixduino built with VSCode and PlatformIO.

  • Blinking of 4 NeoPixels. Of course, you can have different numbers of NexPixels.
  • Blinking by drawing a virtual LED on a 320x240 LCD attached to it with its 24PIN MCU LCD connector.
  • Blinking by drawing a virtual LED on DumbDisplay, a virtual display realized with your Android phone.

First, I will show how you can restore the Maixduino board factory firmware.

Restoring Maixduino Board Factory Firmware

Screenshot 2023-08-26 195005.png

As far as I know, the factory firmware of the Maixduino board is the MaixPy customized MicroPython. Be assured that you can restore (and upgrade) this factory firmware as described by the site Introduction of MaixPy.

According to the page -- Update MaixPy firmware -- to burn MaixPy BIN, you can use the tool kflash_gui that can be downloaded from the page

  • Download the latest version, say, kflash_gui_v1.8.1_windows.7z
  • Use 7-Zip to decompress it to get the executable kflash_gui.exe, the tool to burn firmware to the Maixduino board

You download the latest MaixPy BIN from the page

  • Click on the latest link, say, maixpy_v0.6.2_85_g23d09fbcc to the actual download page. If you see errors, try refreshing the page.
  • Download the last one, say, maixpy_v0.6.2_85_g23d09fbcc.bin. The last one usually is the "factory default firmware version", with naming convention maixpy_vx.y.z_x_xxx*.bin

Burn the downloaded BIN to your Maixduino board with the downloaded kflash_gui tool.

After successful burning of the BIN to your Maxiduino board, the attached LCD should show the default red splash screen that says "Welcome to MaixPy"

Knowing how to restore the factory firmware, you are ready to proceed to program your Maixduino board with Arduino framework, and be able to come back to program your Maixduino board with MicroPython.

Connections With NeoPixels

One of the blink tests involves NeoPixels. The connections are simple

  • Connect 3V3 of Maixduino to VCC of NeoPixels
  • Connect GND of Maixduino to GND of NeoPixels
  • Connect 7 of Maixduino to IN of NeoPixels

A reminder: According to a DFRobot page, the pins of Maixduino board are not 5V tolerated

The shape and pins are compatible with Arduino UNO R3 but the voltage level is not compatible, which requires great attention, otherwise the board can be damaged. Maixduino supports 3.3V and 1.8V levels, and the pins are divided into several BANKs, each BANK can be set to a voltage of 1.8V or 3.3V by software, However, these pins are not 5V tolerated. Therefore, when using the peripheral device of Arduino, be careful not to short the 5V to the pin or RST (1.8V) pin.

Creating PlatformIO Project

device-manager.png

All these 3 blink tests will be housed in a single PlatformIO project. Hence, first, create the PlatformIO project MaixduinoExperiments. Here I will assume that you already have VSCode and Platform VSCode extension installed.

Create a directory, say, called MaixduinoExperiments

Open the directory (folder) with VSCode

From VSCode, at the top level of the folder, create the PlatformIO project configuration file platformio.ini

[env:maixduino]
platform = kendryte210
platform_packages =
  platformio/framework-maixduino@^0.3.9
board = sipeed-maixduino
framework = arduino
lib_deps =
    https://github.com/adafruit/Adafruit_NeoPixel#1.11.1
    https://github.com/trevorwslee/Arduino-DumbDisplay
monitor_speed = 115200
monitor_port = COM12
upload_port = COM12

Note that the Maixduino board actually consists of 2 microcontroller chips

  • Kendryte K210: the main microcontroller that you upload sketch to
  • ESP32: basically a WIFI module for Maixduino

Therefore, when you plug your Maixduino board to your computer, you will see two COM ports for the Maixduino board -- the first one is for K210, the second one is for ESP32

Since it is not reasonable to expect PlatformIO to be able to detect which COM port to upload your sketch to, you specify the COM port with monitor_port and upload_port in platformio.ini

Please find out the COM port to use in your environment with the Device Manager. Note that the COM port likely will stay the same if you plugin your Maixduino board to the same USB plug.

Create the src folder, in which all your programs/sketches should reside.

Create the main entry point src/main.cpp

#include <Arduino.h>
void setup() {
}
void loop() {
}

For now, keep it as "empty"

Make sure it is OK so far by building the "empty" program

Building in release mode
Compiling .pio\build\maixduino\src\main.cpp.o
Checking size .pio\build\maixduino\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.5% (used 32392 bytes from 6291456 bytes)
Flash: [          ]   0.4% (used 67177 bytes from 16777216 bytes)

Blink Test With 2x2 NeoPixels

Although we are using PlatformIO, we will still develop sketches (program files ending with extension .ino). The first sketch is to blink 4 NeoPixels with the Maixduion board.

Going back to the PlatformIO project MaixduinoExperiments.

Create the sketch src/neoblink/neoblink.ino

#include <Adafruit_NeoPixel.h>

#define PIN        7
#define NUMPIXELS  4

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // set up Serial for outputting to serial monitor
  Serial.begin(115200);

  // initial the neo-pixel strip
  pixels.begin();

  // set the brightness
  pixels.setBrightness(1);
}

int idx = 0;
void loop() {
  // print out to the serial monitor which pixel to blink
  Serial.print("blinking pixel @ ");
  Serial.println(idx);

  // set the pixel @ idx to green
  pixels.setPixelColor(idx, pixels.Color(0, 255, 0));
  pixels.show();

  // delay for a second
  delay(1000);

  // turn off the pixel @ idx
  pixels.setPixelColor(idx, 0);
  pixels.show();
 
  // delay for a second
  delay(1000);

  // change idx to next pixel
  idx = (idx + 1) % NUMPIXELS;
}

Note that the macro NUMPIXELS defines how many NeoPixels you actually have.

Next, modify the main entry point src/main.cpp to trick PlatformIO into treating the sketch as the program to build and upload

#include <Arduino.h>
#include "neoblink/neoblink.ino"

That is it.

Now, build and upload the sketch to your Maixduino

  • The 4 NeoPixels should blink in turns in green.
  • You can connect your Maixduino board to a serial monitor (say PlatformIO's default one) to see the progress of the blinking

Blink Test With Attached LCD

You can attach a 320x240 LCD to your Maixduino's 24PIN MCU LCD connector. In fact, when you purchase your Maixduino board, it might already be bundled.

Assume such LCD attachment, you can program a sketch that draws a virtual LED on the LCD for simulating blinking of LED.

Create the sketch src/lcdblink/lcdblink.ino

#include <Sipeed_ST7789.h>

SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
Sipeed_ST7789 lcd(320, 240, spi_);

void setup() {
  // set up Serial for outputting to serial monitor
  Serial.begin(115200);

  // initial the LCD for drawing the virtual LED, and make it green
  lcd.begin(15000000, COLOR_GREEN);
}

bool on = false;
void loop() {
  // print out the LED status to the serial monitor
  Serial.print("LED ");
  Serial.println(on ? "on" : "off");

  // draw the virtual LED as on or off
  lcd.fillCircle(160, 120, 100, on ? COLOR_RED : COLOR_BLUE);

  // toggle the variable on
  on = !on;

  // wait for 1 second before looping
  delay(1000);
}

Then modify the main entry point src/main.cpp to trick PlatformIO into treating the sketch as the program to build and upload

#include <Arduino.h>
#include "lcdblink/lcdblink.ino"

That is it.

Build and upload the sketch to your Maixduino

  • You should see drawn on the LCD a red / blue circle on a green background, simulating LED blinking
  • You can connect your Maixduino to a serial monitor (say PlatformIO's default one) to see the progress of the blinking

Blink Test With DumbDisplay

ddss_0.png
ddss_1.png
ddss_2.png

The sketch of this blink test with DumbDisplay is the same as the sketch mentioned in my previous post -- Blink Test With Virtual Display, DumbDisplay

Create the sketch src/otgblink/otgblink.ino

#include "dumbdisplay.h"

// create the DumbDisplay object; assuming USB connection with 115200 baud
DumbDisplay dumbdisplay(new DDInputOutput(115200));

// declare a LED layer object, to be created in setup()
LedGridDDLayer *led;

void setup() {
    // create the LED layer object, with only a single LED
    led = dumbdisplay.createLedGridLayer();
}

void loop() {
    // toggle the LED
    led->toggle();

    // delay for a second
    delay(1000);
}

Then modify the main entry point src/main.cpp to trick PlatformIO into treating the sketch as the program to build and upload

#include <Arduino.h>
#include "otgblink/otgblink.ino"

That is it.

Build and upload the sketch to your Maixduino.

Assume you have DumbDisplay Android app installed on your Android phone. You can connect your Maxiduino to your Android phone via an OTG adapter (like connecting to your computer), and use the app to connect to your Maixduion board to see the action. Note that you will be seeing two USB devices -- the first one being the K210 and the second one being the ESP32 -- connect to the first one.

Enjoy!

Arduino Framework Blink Tests With SiPEED Maxduino

Hopefully, in the near future, I will develop some more sketches to try out more capabilities of the Maixduino. Until then, enjoy!

Peace be with you! May God bless you! Jesus loves you!.