Created
March 2, 2021 09:07
-
-
Save smetronic/8482972582d72d2cf4af74abeb466b03 to your computer and use it in GitHub Desktop.
Arduino and Raspberry I2C Communication. Send String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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