ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Raspberry Pi and Arduino communications using SPI with Python and CPP

Raspberry pi

Arduino

spi

serial

communications

networking

primary

secondary

main

master

slave

MISO

MOSI

SS

cs

chip

select

raspberry

pi

rpi

atmega328

atmega328p

atmel

microcontroller

microprocessor

freeduino

python

cpp

c++

linux

data

transfer

asynchronous

synchronous

duplex

half-duplex

full-duplex

digital

pin

analog

digitalread

digitalwrite

analogread

computers

computing

somputer

science

stem

electronics

level-shifter

logic

level

convertor

led

Автор: Penguin Tutor

Загружено: 2021-01-11

Просмотров: 24089

Описание: In an earlier I showed how you can control an Arduino from a Raspberry Pi using USB serial communications (UART). In this I show an alternative way to communicate between a Raspberry Pi and an Arduino by using the SPI (Serial Peripheral Interface) protocol.



The advantage of SPI is that you can control multiple devices through one SPI bus. It can also be faster. It is however a little more complicated to understand and code and I've not properly used the full-duplex feature in my example code.

For more details and to download the source code see:
http://www.penguintutor.com/electroni...

This video is created thanks to a suggestion from Gari Poter on the earlier video    • Arduino and Raspberry Pi, working together...  


The SPI ports on the Raspberry Pi are 3.3V only. They can be damaged by if a slave device raises a bus to 5V. If connecting to a 5V device then a level shifter should be used. Based on all models of the Raspberry Pi with 40pins, the pins for SPI0 are (physical pins):
MOSI - pin 19
MISO - pin 21
SCLK - pin 23
CE0 - pin 24
CE1 - pin 26
Ground - pin 25


Different models of the Arduino have different capabilities and ports for SPI. The newer MKR series run at 3.3V, but the more common UNO runs at 5V. I tested this using a Freeduino UNO which has the advantage of being able to switch between 3.3V and 5V, but otherwise similar to the official Arduino. It did have the advantage of allowing me to test the connection was working using 3.3V prior to adding the level shifter.

The ports on the Arduino UNO that are used are:
MOSI - pin 11
MISO - pin 12
SCLK - pin 13
SS / CE - pin 10 (optional)


Due to the voltage difference I suggest that you use a logic level convertor (sometimes called a level-shifter or voltage shifter) between the Raspberry Pi and Arduino. The model I used is the "4-channel I2C-safe Bi-directional Logic Level Converter - BSS138". This is designed for I2C, but also works well with SPI up to 2Mhz.


For test purposes I have connected digital outputs 3 to 9 to LEDs and resistors to ground. I used a bar graph LED and resistor array for convenience, but did not use all the LEDs on the bar graph. I used digital pin 2 to test an input (moving between +5V and Gnd) and I also added a variable resistor so that I could measure an analog voltage on analog input A0. This is shown in the diagram below (for convenience this is turned 90 degrees compared with the earlier diagram).


This allows the code to demonstrate two way communication, with the Raspberry Pi asking the Arduino to set digital outputs on or off and request the Arduino provide information about digital and analog inputs. The Arduino sends the relevant information back to the Raspberry Pi. This provides something that can be used as a standalone system, although it's really just a small demonstration of what you can do.


Chapters:
00:00 Introduction to video
00:39 Introduction to SPI
02:37 The difference between UART / USB serial and SPI
05:48 Communicating with multiple devices by SPI
06:10 Handling voltage difference between Raspberry Pi and Arduino
07:24 Test setup
07:58 Creating my own protocol for sending data with bitmasks
09:32 Arduino code in C++
10:58 Raspberry Pi code using Python
12:34 Summary and demo

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Raspberry Pi and Arduino communications using SPI with Python and CPP

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Transistor switch circuit for Raspberry Pi, Arduino and micro:bit

Transistor switch circuit for Raspberry Pi, Arduino and micro:bit

Using a Raspberry Pi to Program an AVR and Python SPI Tutorial

Using a Raspberry Pi to Program an AVR and Python SPI Tutorial

Руководство для начинающих по SPI на Raspberry Pi Pico (пример BMP280)

Руководство для начинающих по SPI на Raspberry Pi Pico (пример BMP280)

Sending Data via I2C (RaspberryPi to Arduino) How to Wire & Code

Sending Data via I2C (RaspberryPi to Arduino) How to Wire & Code

Последовательная связь Raspberry Pi и Arduino через GPIO с помощью Python

Последовательная связь Raspberry Pi и Arduino через GPIO с помощью Python

Raspberry Pi to Arduino Serial USB Communication

Raspberry Pi to Arduino Serial USB Communication

I2C на Raspberry Pi — КАК использовать I2C с Python

I2C на Raspberry Pi — КАК использовать I2C с Python

SPI: последовательный периферийный интерфейс

SPI: последовательный периферийный интерфейс

[ENG] Raspberry Pi! Ep: 4 - SPI Usage - C (spidev)

[ENG] Raspberry Pi! Ep: 4 - SPI Usage - C (spidev)

Последовательная связь Raspberry PI Arduino — Часть 1

Последовательная связь Raspberry PI Arduino — Часть 1

Как подключить аналого-цифровой преобразователь (АЦП) MCP3008 к Raspberry Pi и Arduino

Как подключить аналого-цифровой преобразователь (АЦП) MCP3008 к Raspberry Pi и Arduino

Raspberry Pi - I2C Communications

Raspberry Pi - I2C Communications

I2C — Raspberry Pi, Pico и Arduino

I2C — Raspberry Pi, Pico и Arduino

15 лучших проектов Интернета вещей 2025 года 🤯!

15 лучших проектов Интернета вещей 2025 года 🤯!

SPI in a nutshell + Arduino & Raspberry Pi implementation: Electronics Crash Course 14

SPI in a nutshell + Arduino & Raspberry Pi implementation: Electronics Crash Course 14

Arduino - Read Serial Communication with Raspberry Pi

Arduino - Read Serial Communication with Raspberry Pi

TRIPLE the WiFI RANGE of your ESP32 C3 using ONE wire! #esp32

TRIPLE the WiFI RANGE of your ESP32 C3 using ONE wire! #esp32

Use a Raspberry Pi to power and parse data from an Arduino (EASY!)

Use a Raspberry Pi to power and parse data from an Arduino (EASY!)

Как я с нуля сделал ноутбук на базе C64 — Portable 64 (эмуляция)

Как я с нуля сделал ноутбук на базе C64 — Portable 64 (эмуляция)

Raspberry Pi Tutorial 38 - Use an Arduino as a Slave with Python (Nanpy)

Raspberry Pi Tutorial 38 - Use an Arduino as a Slave with Python (Nanpy)

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]