STM32 Thing Plus Hookup Guide

Pages
Contributors: Alex the Giant, Ell C
Favorited Favorite 1

Example - Serial UART

Let's have a quick look at an example using UART. If you're unfamiliar with Serial Output, go ahead and have a look at our Serial Basic Tutorial.

Grab your MicroMod STM32 Thing Plus board and attach the Serial Basic Rx and Tx pins like so:

Hookup image showing Rx connected to Tx and Tx connected to Rx

Click on the image for a closer view

Note that the RX pin functionality is D0 and the TX pin functionality is D1.

Copy and paste the code below into a new Arduino sketch.

language:c
// --------------------------------------
// UART example using Serial1
//
//
// This sketch prints "Hello World!" every second
// using the secondary UART pins D0 and D1.
//



HardwareSerial Serial1(D0, D1); //Attach Serial1 to D0 and D1

void setup() {
  Serial1.begin(115200);
  while (!Serial1) {
    ; // wait for serial port to connect. Needed for Native USB only
  }
  Serial1.println("Goodnight moon!");

}

void loop() {
  Serial1.println("Hello World!");
  delay(1000);
}

Make sure your options are all set up correctly in the Tools menu, and make sure you put your board into Boot Mode in order to upload the code.

  • Press and hold down the Boot button
  • Press and release the Reset button while continuing to press the Boot button
  • Release the Boot button and press the Upload button in your Arduino IDE

Once your code is uploaded, open up the Serial Monitor attached to your Serial Basic with the baud set to 115200 to see your output!

Gif of the serial output printing "Hello World" every second