LoPy - Arduino Serial Communication

LoPy - Arduino Serial Communication © CC BY-SA

Serial communication between the Pycom LoPy and the Arduino Uno.

  • 4,234 views
  • 1 comment
  • 10 respects

Components and supplies

About this project

Introduction

Between the Arduino Uno and the Pycom Lopy a connection can be made through an UART bus, a bi-directional serial communication.

The result on the Lopy to test the connection:

 PYB: soft reboot 
==========Starting main.py========== 
Main start 
None 
b'Lopy, did you say: Hello Arduino?\r\n' 
b'Lopy, did you say: Hello Arduino?\r\n' 
b'Lopy, did you say: Hello Arduino?\r\n' 

This is how it looks all wired up (sorry for the colouring of the wires):

Components

For the Arduino we will use an Arduino Uno with the ATmega328P chip.

Please note that the Lopy IO-pins are not 5V tolerant, so that's why we need the logical level converter. This basically converts the 5V down to the logic level of the Lopy, which is 3.3V, and the other way around.

The protoshield can be used if you want to attach both devices together for prototyping or a bit more permanent by soldering. The shield attaches to the Arduino Uno and provides a nice way to integrate the Lopy with the Arduino. You can also use a breadboard for testing purposes of course.

Connecting the parts

Connect the GND and 3.3V from the Lopy to the low side of the LLC, to GND and LV respectively.

The Arduino has it's 5V and GND connected on the high side on corresponding pins.

RX and TX pins for serial communication are one-way. This means that the TX pin of the Arduino needs to be connected to the RX pin of the Lopy and vice versa. Again the Lopy pins go on the low side of the LLC and the Arduino pins on the high voltage side. The ports are linked straight from the low side to the high side, so which of the 4 channels you use doesn't matter.

Power up both the Lopy and the Uno. Connect the Lopy with an usb-cable from your pc to the expansion board. Connect the Uno to a 5V usb-adapter.

Open up PyMakr or a telnet client and connect your Lopy.

The Lopy will start with its boot script, initializing the two UART buses. The main script will then every second send a message to the Uno. If everything is wired up correctly you should see the Uno talking back, cool!

Code

Lopy: boot.pyPython
Upload this script to the /flash directory on the Lopy.
"""Setup serial communication between Lopy, Arduino and PC.
Disable LED.
"""
import os
import machine
import pycom


# Configure first UART bus to see the communication on the pc
uart = machine.UART(0, 115200)
os.dupterm(uart)

# Configure second UART bus on pins P3(TX1) and P4(RX1)
uart1 = machine.UART(1, baudrate=9600)

pycom.heartbeat(False)

machine.main('main.py')
print('==========Starting main.py==========\n')
Lopy: main.pyPython
Upload this script to the /flash directory on the Lopy.
"""Sends a string to the Arduino. Waits one second and then reads the answer
from the Arduino.
"""
import time


print('Main start')

while True:
    uart1.write('Hello Arduino')
    time.sleep(1)
    print(uart1.readline())  # read the response from the Arduino
    time.sleep(1)
Arduino: serialCom.inoArduino
Upload this script to your Arduino Uno.
void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0){ // at least one byte is available from the Lopy
    // read the message from the Lopy
    String msg = Serial.readStringUntil('\n');
    // and repeat the message back
    Serial.println("Lopy, did you say: " + msg + "?");
  }
}

Schematics

Hookup guide
Hookup gxtevrcb12

Comments

Similar projects you might like

Serial Communication between NodeMCU and Arduino

Project showcase by Pawan Kumar

  • 10,747 views
  • 2 comments
  • 14 respects

Arduino - Serial Communication Visual Studio

Project tutorial by whitebank

  • 16,291 views
  • 5 comments
  • 16 respects

Spark (3.3v) to Arduino (5v) Serial Communication

Project tutorial by Garrett Bartley

  • 5,423 views
  • 0 comments
  • 13 respects

Communication Between Arduino UNO

by Giovanni Gentile

  • 2,528 views
  • 1 comment
  • 4 respects
Add projectSign up / Login