TinyCircuits Forum

General Category => General Discussion => Topic started by: Gerardo on May 16, 2023, 11:29:03 PM

Title: Serial communication with TinyScreen+
Post by: Gerardo on May 16, 2023, 11:29:03 PM
Good Day guys I got some questions about the serial communication.

I understand that the USB serial and the Serial on the board are separate ports as if I want to see some info on the serial monitor on the screen I have to use SerialUSB. print ("something") but how can I use the TX and RX on the board? how should I call them? also what is the voltage that I need? I know arduino is 5v on the logic levels but not sure about Tiny Screen+, I got a project where I have to connect a ESP32 Feather to a TinyScreen+ and the Feather works with 3.3v levels.

I'm a bit lost and will appreciate all the help in this matter.

Cheers
Gerardo
Title: Re: Serial communication with TinyScreen+
Post by: Jason on May 17, 2023, 11:25:04 AM
Good Day guys I got some questions about the serial communication.

I understand that the USB serial and the Serial on the board are separate ports as if I want to see some info on the serial monitor on the screen I have to use SerialUSB. print ("something") but how can I use the TX and RX on the board? how should I call them? also what is the voltage that I need? I know arduino is 5v on the logic levels but not sure about Tiny Screen+, I got a project where I have to connect a ESP32 Feather to a TinyScreen+ and the Feather works with 3.3v levels.

I'm a bit lost and will appreciate all the help in this matter.

Cheers
Gerardo

Hello,

For voltage, the TinyScreen+ should work with 3.3V since the operating voltage range is 2.7V ~ 5.5V. You can check that yourself in "Tech Specs" on this page https://tinycircuits.com/products/tinyscreenplus (https://tinycircuits.com/products/tinyscreenplus).

Most of the information you are looking for can be found in the boards package for our samd21 based processor boards. You can download the latest boards package at this link: https://github.com/TinyCircuits/Arduino-Boards/raw/main/Packages/tinycircuits-samd-1.1.0.zip (https://github.com/TinyCircuits/Arduino-Boards/raw/main/Packages/tinycircuits-samd-1.1.0.zip). You can extract that if you would like to follow along with how I figured this out.

Looking at the SAMD21 datasheet (https://ww1.microchip.com/downloads/en/DeviceDoc/SAM-D21DA1-Family-Data-Sheet-DS40001882G.pdf (https://ww1.microchip.com/downloads/en/DeviceDoc/SAM-D21DA1-Family-Data-Sheet-DS40001882G.pdf)) I saw some stuff about SERCOM that can be used for extra serial ports. Next, I checked the variant files (standard Arduino board package files) called ''variant.h' and variant.cpp' which are located at 'tinycircuits-samd-1.1.0\1.1.0\variants\tinyscreen_p'. I checked these to see if there was any usage of the extra ports first (just had a hunch that they might be used or exposed in an Arduino kind of way).

You can see at the bottom of 'variant.h' that there are some extra SERCOM UART objects:
Code: [Select]
extern Uart Serial;
extern Uart Serial1;

At the bottom of 'variant.cpp' you can see
Code: [Select]
// Multi-serial objects instantiation
SERCOM sercom0( SERCOM0 ) ;
SERCOM sercom1( SERCOM1 ) ;
SERCOM sercom2( SERCOM2 ) ;
SERCOM sercom3( SERCOM3 ) ;
SERCOM sercom4( SERCOM4 ) ;
SERCOM sercom5( SERCOM5 ) ;

Uart Serial( &sercom0, PIN_SERIAL_RX, PIN_SERIAL_TX, PAD_SERIAL_RX, PAD_SERIAL_TX ) ;
Uart Serial1( &sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;

So now we need to find which pins are associated with SERCOM0 and SERCOM5 and see if they're exposed on our protoboard shield (https://tinycircuits.com/products/proto-board-tinyshield (https://tinycircuits.com/products/proto-board-tinyshield)). Using the protoboard shield should be fairly easy, but we also have a solution for solderless connections with this shield https://tinycircuits.com/products/proto-terminal-blocks-tinyshield (https://tinycircuits.com/products/proto-terminal-blocks-tinyshield). We'll need to check that the correct pins are exposed for SERCOM0 or SERCOM5.

Looking at the top comment in 'variant.cpp' we can see a list of pins and their relation to each SERCOM port (as well as a bunch of extra stuff). Glancing around we see that each SERCOM port has 4 pins (we should only need two though for UART, we'll figure that out later, the extra pins are probably so you can setup SPI or other protocols). Looking at the comment we see the following:

SERCOM0 pins:

SERCOM5 pins:

Now that we know all the pins we need, let's see if they're exposed through the proto or terminal shields.

Here's a list of schematics we'll need to look through:

Looking at the TinyScreen+ schematic we can see that the pins for SERCOM0 get called the following:

SAMD21/SERCOM0  pins to TinyScreen+ schematic pins:

Now looking at the schematic for the solder proto shield we can see in the "External Connections" block that IO0, IO1, IO3, and IO4 are exposed on through-hole pads on the shield. On the product page (https://tinycircuits.com/products/proto-board-tinyshield (https://tinycircuits.com/products/proto-board-tinyshield)) in the 4th picture you can see where these pins are physically located.

Turns out those pins are also available on the solderless terminal block shield too. In the schematic they are located on J2 and are called "0 RX" and "1 TX" on the physical PCB. Since we only need one extra serial port, we won't verify if SERCOM5 has exposed pins.

Knowing all of that, you should be able to use the 'Serial' object (not 'SerialUSB' and not 'Serial1') to run the "0 RX" and "1 TX" pins on the terminal shield, or likely pins 'IO0' (RX) and '1' (TX) as marked on the proto board shield. As you know, the functions you'll have available should be mostly the same as is listed here: https://www.arduino.cc/reference/en/language/functions/communication/serial/#:~:text=your%20device%E2%80%99s%20ground.-,Functions,-if(Serial) (https://www.arduino.cc/reference/en/language/functions/communication/serial/#:~:text=your%20device%E2%80%99s%20ground.-,Functions,-if(Serial))

That's a lot of information, but I wanted to give you the path I followed to verify everything. Hopefully the information I gave you works, otherwise you could try debugging it through the information above or you can ask me more questions.

Hope this helps!