diff options
| author | Abel Tim <abel@main.home> | 2024-06-03 17:38:19 +0200 |
|---|---|---|
| committer | Abel Tim <abel@main.home> | 2024-06-03 17:38:19 +0200 |
| commit | 51051da4e85ae296bedb6d3709947e5311deee07 (patch) | |
| tree | aa034dfada5c121e4e00d82d131c0d9de919cef5 /comm/i2c/i2c_arduino_master | |
| parent | 2f2acda8dc9fd863a1e45abca2efe185a42563d5 (diff) | |
| download | robotica-51051da4e85ae296bedb6d3709947e5311deee07.tar.gz robotica-51051da4e85ae296bedb6d3709947e5311deee07.zip | |
update com
Diffstat (limited to 'comm/i2c/i2c_arduino_master')
| -rw-r--r-- | comm/i2c/i2c_arduino_master/i2c_arduino_master.ino | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/comm/i2c/i2c_arduino_master/i2c_arduino_master.ino b/comm/i2c/i2c_arduino_master/i2c_arduino_master.ino new file mode 100644 index 0000000..ff960ed --- /dev/null +++ b/comm/i2c/i2c_arduino_master/i2c_arduino_master.ino @@ -0,0 +1,36 @@ +#include <Wire.h> +#define BAUD_RATE 19200 +#define CHAR_BUF 128 + +void setup() { + Serial.begin(BAUD_RATE); + Wire.begin(); + delay(1000); // Give the OpenMV Cam time to bootup. +} + +void loop() { + int32_t temp = 0; + char buff[CHAR_BUF] = {0}; + + Wire.requestFrom(0x12, 2); + if(Wire.available() == 2) { // got length? + + temp = Wire.read() | (Wire.read() << 8); + delay(1); // Give some setup time... + + Wire.requestFrom(0x12, temp); + if(Wire.available() == temp) { // got full message? + + temp = 0; + while(Wire.available()) buff[temp++] = Wire.read(); + + } else { + while(Wire.available()) Wire.read(); // Toss garbage bytes. + } + } else { + while(Wire.available()) Wire.read(); // Toss garbage bytes. + } + + Serial.print(buff); + delay(1); // Don't loop to quickly. +} |
