Using I2C on the Maple Mini
Posted: Mon May 25, 2020 3:01 pm
Hello,
to first give you broad idea what I'm going for, my plan is to do the following:
Now I've tried to somewhat reproduce that in a similar manner for the Maple as follows:
Unfortunately the code has a minor problem of completely not working at all and my attempts to debug it haven't been very fruitful. I've not been successful in locating a working i2c example for this board either so I don't have much to go from.
So my question is, how to properly set up both of the i2c busses for usage at the same time (why do we have two of them otherwise eh?), and before that - how to even get one working properly in the first place.
Thanks!
to first give you broad idea what I'm going for, my plan is to do the following:
- link one TCA9548A to each of the two i2c ports of the maple mini (pins PB6/7 and PB11/10 according to the pinout)
- add 8 VL53L0X linear lidars to the first one
- add 4 US42-V2 sonars to the second one
- read them all sequentially and send the results via serial
Code: Select all
import smbus
import time
i2cbus = smbus.SMBus(1)
address = 0x70
i2cbus.write_byte(address, 0x51)
time.sleep(0.12)
val = i2cbus.read_word_data(address, 0xe1)
print (val >> 8) & 0xff | (val & 0xff), 'cm'
Code: Select all
#include<Wire.h>
#define US42 0x70
void write_byte(int dev_addr, byte addr){
Wire.beginTransmission(dev_addr);
Wire.write(addr);
Wire.endTransmission();
}
int read_word_data(int dev_addr, byte number){
Wire.requestFrom(dev_addr, number);
while(Wire.available() == 0);
return Wire.read();
}
void setup() {
I2C1->sda_pin = PB7;
I2C1->scl_pin = PB6;
Wire.begin();
}
void loop() {
write_byte(US42, 0x51);
delay(120);
int val = read_word_data(US42,2);
val = (val >> 8) & 0xff | (val & 0xff);
Serial.write(val);
}
So my question is, how to properly set up both of the i2c busses for usage at the same time (why do we have two of them otherwise eh?), and before that - how to even get one working properly in the first place.
Thanks!
