element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Off the Shelf
  • Challenges & Projects
  • Project14
  • Off the Shelf
  • More
  • Cancel
Off the Shelf
Blog Arduino Nano as Raspberry Pi IO I2C expander PART 3 - Python Voodoo - the I2C bus - byte me !!
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Off the Shelf to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: robogary
  • Date Created: 22 Sep 2021 1:14 AM Date Created
  • Views 963 views
  • Likes 1 like
  • Comments 0 comments
  • offtheshelfch
Related
Recommended

Arduino Nano as Raspberry Pi IO I2C expander PART 3 - Python Voodoo - the I2C bus - byte me !!

robogary
robogary
22 Sep 2021

Off the shelf Part 3  - Getting the I2C to talk

there are several simple examples of Raspberry Pi to Arduino I2C on the web

In studying them, I'd selected on in particular example that was a best fit:

  • demonstrated both data read & write
  • used a recognized standard library
  • coding was straightforward, easy to read   

https://oscarliang.com/raspberry-pi-arduino-connected-i2c/

none of the examples I found exchanged multiple bytes.

 

Like many examples on the web, even a proven code example need some extra love.

This program has the user enter a value into the Raspberry Pi Python window, the Arduino reads the value and sends it back.

In this case, the quotation marks didn't translate on copy, and the Raspberry Pi code lost indent format  - no biggie to fix that part

 

However on RUN, the Python Shell complained  the keyboard input number was not an integer but a string.

WELLL.......... I'm not so smart, so a line of code is added to convert string to a byte, thats what the code is reading and writing.

Now the VOODOO , Python tells me again an integer is required to write a byte.

OK, I cave , add a line to converter a string to integer and behold the data comes to life and the example

code is working. 

However , also take note that as integer values bigger than a byte are entered, they are truncated to a byte.

image

its working now

image

 

image

 

YEA ! 

The next STEP is to have the Arduino send multiple bytes to the Raspberry Pi using I2C.

BYTE ME !!

  • More investigation for writing multiple bytes from the Arduino to RPi, several tries , it is not working yet.
  • The Raspberry Pi  byte array always displays the value of array [0] in all locations of the byte array. See Screen 4
  • Troubleshooting the Arduino code, the 5 bytes of data, 2 bytes for the up/dwn joystick position, 2 bytes for the

left/right joystick , and an extra byte for later use, is being loaded into a byte matrix correctly.  see Screen 5

The scheme shown in screen 5 is in the main loop. 

  • maybe the array values cant be seen by the void SendData() function, so all the array code and reading of analog inputs

were moved to void SendData()  - see Screen 6 - it made no difference

 

 

screen 4

image

screen 5

image

screen 6

image

 

Next up,  a gris-gris and a good Python potion for the next attempt of.........send me some bytes from the Nano. 

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube