Arduino to Raspberry Pi Communication: Interface Options and I2C Overview

Arduino to Raspberry Pi Communication: Interface Options and I2C Overview
Slide Note
Embed
Share

"Explore methods to interface external devices with Raspberry Pi, including UART, USB, I2C, and SPI. Learn about I2C communication, its roles, address space, and key points for successful implementation. Discover I2C sensors for robotics projects."

  • Arduino
  • Raspberry Pi
  • I2C
  • Interface Options
  • Robotics

Uploaded on Mar 05, 2025 | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Arduino to Raspberry Pi Communication w: nexgencodecamp.com.au t: 1800 940 955 e: iot@nexgencodecamp.com.au

  2. The IoT Robotics Challenge INTERFACE OPTIONS NEXGEN CODECAMP When you interface external devices to the Pi (including the Arduino), in addition to the GPIO you have a number of other options, including: UART (serial) USB I2C SPI One Wire Some other exotic protocol We will review the most popular options and then use Serial (via USB) to communicate with an Arduino.

  3. The IoT Robotics Challenge NEXGEN CODECAMP I2C I C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips. It is typically used for attaching lower-speed peripheral ICs to microcontrollers for short-distance communication. SMBus, defined by Intel in 1995, is a subset of I C, defining a stricter usage. I C uses only two bidirectional lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V. Common I C bus speeds are the 100 kbit/s standard mode and the 10 kbit/s low-speed mode.

  4. The IoT Robotics Challenge NEXGEN CODECAMP I2C The I C reference design has a 7-bit or a 10-bit (depending on the device used) address space. The maximum number of nodes is limited by the address space, and also by the total bus capacitance of 400 pF, which restricts practical communication distances to a few meters. The bus has two roles for nodes: master and slave: Master node node that generates the clock and initiates communication with slaves Slave node node that receives the clock and responds when addressed by the master The bus is a multi-master bus which means any number of master nodes can be present. Additionally, master and slave roles may be changed between messages (after a STOP is sent).

  5. The IoT Robotics Challenge I2C Key Points NEXGEN CODECAMP 2 wire system which supports up to 1008 slaves. unlike SPI, I2C can support a multi-master system, allowing more than one master to communicate with all devices on the bus. However masters can t communicate with each other. Data rates fall between asynchronous serial and SPI; most I2C devices can communicate at 100kHz or 400kHz.

  6. The IoT Robotics Challenge I2C Sensors NEXGEN CODECAMP Magnetometer Light Humidity Temperature UV

  7. The IoT Robotics Challenge NEXGEN CODECAMP SPI The Serial Peripheral Interface bus (SPI) is a synchronous serial communication interface specification used for short distance communication, primarily in embedded systems. The interface was developed by Motorola in the late eighties and has become a de facto standard. Typical applications include Secure Digital cards and liquid crystal displays. SPI devices communicate in full duplex mode using a master-slave architecture with a single master. Multiple slave devices are supported through selection with individual slave select (SS) lines. Sometimes SPI is called a four-wire serial bus, contrasting with three-, two-, and one-wire serial buses.

  8. The IoT Robotics Challenge NEXGEN CODECAMP SPI The SPI bus specifies four logic signals: SCLK: Serial Clock (output from master). MOSI: Master Output, Slave Input (output from master). MISO: Master Input, Slave Output (output from slave). S S : Slave Select (active low, output from master). Alternative naming conventions are also widely used, and SPI port pin names for particular IC products may differ.

  9. The IoT Robotics Challenge NEXGEN CODECAMP SPI - Key Points The most obvious drawback of SPI is the number of pins required. Connecting a single master to a single slave with an SPI bus requires four lines; each additional slave requires one additional chip select I/O pin on the master. SPI only allows one master on the bus, but it does support an arbitrary number of slaves (subject only to the drive capability of the devices connected to the bus and the number of chip select pins available). SPI is good for high data rate full-duplex (simultaneous sending and receiving of data) connections, supporting clock rates upwards of 10MHz.

  10. The IoT Robotics Challenge NEXGEN CODECAMP 1-WIRE Protocol 1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed data, signaling, and power over a single conductor. 1-Wire is similar in concept to I C, but with lower data rates and longer range. It is typically used to communicate with small inexpensive devices such as digital thermometers and weather instruments. A network of 1-Wire devices with an associated master device is called a MicroLAN. One distinctive feature of the bus is the possibility of using only two wires: data and ground. To accomplish this, 1-Wire devices include an 800 pF capacitor to store charge, and to power the device during periods when the data line is active.

  11. The IoT Robotics Challenge NEXGEN CODECAMP 1-Wire Protocol In any MicroLan, there is always one master in overall charge, which may be a PC or a microcontroller. The master initiates activity on the bus, simplifying the avoidance of collisions on the bus. Each device on the bus has a unique 64-bit serial number. The least significant byte of the serial number is an 8-bit number that tells the type of the device. Data rates of 16.3 kbit/s can be achieved. Works up to 300 m with twisted pair telephone cable.

  12. The IoT Robotics Challenge NEXGEN CODECAMP SERIAL Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. I2C and SPI are both implementations of the serial architecture. Asynchronous serial communication is a form of serial communication in which the communicating endpoints' interfaces are not continuously synchronized by a common clock signal. The data stream contains synchronization information in the form of start and stop signals.

  13. The IoT Robotics Challenge NEXGEN CODECAMP Serial Key Points Because serial ports are asynchronous, devices using them must agree ahead of time on a data rate. Differences between clock rates on either device will cause garbled data. Asynchronous serial ports require hardware overhead the UART at either end is relatively complex and difficult to accurately implement in software. At least one start and stop bit is a part of each frame of data, meaning that 10 bits of transmission time are required for each 8 bits of data sent. inherently suited to communications between two, and only two, devices. While it is possible to connect multiple devices to a single serial port, bus contention becomes an issue. Highest baud rate is usually around 230400 bits per second. ADVANTAGE = distance and cost

  14. The IoT Robotics Challenge NEXGEN CODECAMP Serial on the Raspberry Pi GPIO The Raspberry Pi serial port consists of a 'transmit' signal, TxD and a 'receive' signal RxD available on the GPIO header or via USB. To connect to another serial device, you connect the 'transmit' of one to the 'receive' of the other, and vice versa. You will also need to connect the Ground pins of the two devices together. The Broadcom chip uses 0 and 3.3 V logic levels, not the +/-12 V used by RS-232 on a PC, or 0 to 5V on an Arduino UNO. To connect the Raspberry Pi GPIO to a PC USB port, use a USB- to-serial cable which uses 3.3 V logic levels or connect USB to USB If connecting UNO TTL Serial to the Pi GPIO, you need a voltage level converter or again connect via USB. For the RPi v3 you might need to add the option enable_uart=1 at the end of /boot/config.txt.

  15. The IoT Robotics Challenge Interfacing the PI and Arduino NEXGEN CODECAMP For this exercise we will connect the Raspberry Pi to the Arduino UNO using USB. Voltage level conversion is handled by USB adaptor. This exercise will demonstrate bi-directional communication between the Pi and Arduino. First we need to determine the name of the USB port that the Arduino is connected to. On the Pi, type the following with and without the Arduino connected. ls /dev/tty* The name is usually: /dev/ttyACM0

  16. The IoT Robotics Challenge Minicom NEXGEN CODECAMP Minicom is a text-based modem control and terminal emulation program. To install: sudo apt-get install minicom We can use it to emulate the Arduino IDE Serial Monitor. minicom -b 115200 -o -D /dev/ttyACM0 Use the baud rate selected in your Arduino sketch (e.g. 115,200) and the USB port name established earlier.

  17. The IoT Robotics Challenge Minicom NEXGEN CODECAMP Comms are bi-directional. The Pi will receive serial output from the Arduino and vice versa. To exit minicom <enter>, CTRL a, q, <enter>

  18. The IoT Robotics Challenge NEXGEN CODECAMP Pi Serial Using Python To test that we are receiving the information from the Arduino, create this simple python program and run it. import serial arduino_serial = serial.Serial('/dev/ttyACM0', 115200) try: while True: print(arduino_serial.readline()) except KeyboardInterrupt: print("Terminating program.") finally: print("EXIT")

  19. The IoT Robotics Challenge Test tx from Raspberry pi NEXGEN CODECAMP Transmitting is similar. import serial, time arduino_serial = serial.Serial('/dev/ttyACM0', 115200) try: arduino_serial.write( a ) time.sleep(5) except KeyboardInterrupt: print("Terminating program.") finally: print("EXIT")

  20. The IoT Robotics Challenge Serial Input Characteristics NEXGEN CODECAMP bi-directional the Arduino transmits characters (actually, 8-bit values which are interpreted as ASCII characters) which are received by the Pi, and vice versa. full-duplex Arduino-to-Pi transmission can happen at the same time as the Pi-to-Arduino transmission. byte-oriented - each byte is transmitted and received independently of the next byte. In other words, the serial communication does not group transmitted data into packets.

  21. The IoT Robotics Challenge NEXGEN CODECAMP Appendix A

  22. The IoT Robotics Challenge ARDUINO IDE on Raspberry Pi NEXGEN CODECAMP To install the Arduino IDE on the Raspberry Pi: sudo apt-get install arduino If this doesn t work use: mkdir ~/Applications cd ~/Applications wget https://downloads.arduino.cc/arduino-1.8.0- linuxarm.tar.xz tar xvJf arduino-1.8.0-linuxarm.tar.xz cd arduino-1.8.0/ ./install.sh rm ../arduino-1.8.0-linuxarm.tar.xz Or download for your OS (Windows, macOS) at: https://www.arduino.cc/en/main/software

More Related Content