Skip to content

Instantly share code, notes, and snippets.

@smetronic
Created March 2, 2021 09:07
Show Gist options
  • Save smetronic/8482972582d72d2cf4af74abeb466b03 to your computer and use it in GitHub Desktop.
Save smetronic/8482972582d72d2cf4af74abeb466b03 to your computer and use it in GitHub Desktop.
Arduino and Raspberry I2C Communication. Send String
#include <Wire.h>
#define SLAVE_ADDRESS 0x2A
void setup() {
// initialize i2c as slave
Wire.begin(SLAVE_ADDRESS);
Wire.onRequest(sendData);
}
void loop() {
}
char data[] = "123456789123456";
int index = 0;
// callback for sending data
void sendData() {
Wire.write(data[index]);
++index;
if (index >= 15) {
index = 0;
}
}
#!/usr/bin/python
import smbus
import time
bus = smbus.SMBus(1)
address = 0x2a
while True:
data = ""
for i in range(0, 15):
data += chr(bus.read_byte(address));
print(data)
time.sleep(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment