I2c set up on motor2040

Hi,

I cannot get i2c on the motor2040 to pick up any addresses. I am using Micropython and pins 20 and 21.
Are these the correct pin numbers. I got them from the schematic drawing.

Ideally I would like to use the motor2040 as a slave to the pi zero w as the master to control a 4 wheel drive robot via an 8bitdo pro2 Bluetooth controller.

When I have managed that, I want to write some code to make it autonomous using various sensors, hence the want for i2c use

I would appreciate any help. I am using python3 and Micropython, but am a newbie to both.

Thanks

Can you please post the code your using.
i2c = PimoroniI2C(sda=(20), scl=(21))
Is what I use for setting the pins used on similar setups. I don’t have a motor2040, just so you know.
When scanning i2c I use the following code

import machine
sda=machine.Pin(20) # Explorer 20 Breakout 4
scl=machine.Pin(21) # Explorer 21 Breakout 5
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
 
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
  for device in devices:  
    print("Decimal address: ",device," | Hex address: ",hex(device))

The code i am trying to use is the same.
i2cscan.py

import machine
sda=machine.Pin(20)
scl=machine.Pin(21)

i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

print(‘Scan i2c bus…’)
devices = i2c.scan()

if len(devices) == 0:
print(“No i2c device !”)
else:
print(‘i2c devices found:’,len(devices))

for device in devices:
print("Decimal address: “,device,” | Hexa address: ",hex(device))

this is the output :

%Run -c $EDITOR_CONTENT
Scan i2c bus…
No i2c device !

And this is what the pizerow attached sees:
pizero1@pizero1:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – 27 – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
pizero1@pizero1:~ $

i am using the latest pimoroni micropython 1.20
The scanner code works on a pico.

I am beginning to wonder if the board is faulty.

thanks
Dave

Is the i2c device plugged into the QWICC connector on the Motor2040?

At the moment I have it connected to the scl and SDA terminals on the board. I think I have tried it through the qwiic as well, but I will try it to see if it makes a ny difference. Will it be the same pin out on the scanner.

Thanks
Dave

It should be the same pins used either way.

I just tried it on qwiic connections and still nothing.
i then put the 3.3v and ground from the motor 2040 and put them with pin 20 and 21 on a pico,
which picks up the lcd screen straight away.
can i check i2c pins with a multimeter.

thanks dave

i am using Micropython v1.20.2. raspberry pi pico with rp2040.
with pimoroni libraries.

If you want to runt the motor2040 as a slave, you have to implement slave (device) mode for the motor2040. I.e. write your own firmware. The MP on the motor2040 will always assume it is the master.

I have tried some code of the web for using the Pico as a slave. I changed the pin numbers to 20 and 21 and I couldn’t get it working.
I can’t seem to get anything out of the i2c pins either as a slave or master. I have the motor 2040 connected to the pi over USB. The connections to the LCD are 3.3v , ground, scl, and sda. It works with the Pico but not motor 2040.

I assume that when you run your i2c-scan program on the motor2040, nothing else is connected? Besides the Pi of course, but in this case the Pi would only supply power and give you access to the serial console?!

This really sounds like a hardware problem then.

Checking I2C with a multimeter is difficult. You should always see HIGH, since SDA and SCL are pulled up. Only during data-transmission they are LOW, but a multimeter is not fast enough to pick this up. You need a oscilloscope for this. Or a logic-analyzer. I use this one: GitHub - gusmanb/logicanalyzer: 24 channel, 100Msps logic analyzer hardware and software
It is simple and cheap, you only need a pico as a probe and a host (windows, Linux, PiOS are all supported) to run the code.

But given all that you have done I would suggest that you ask Pimoroni for a replacement unit.

I will have a look at the logic analyser when I get a moment. I also think that the problem is with the board. I can get UART working on it, and the code for i2c works on a Pico.
It’s a pity I don’t have another rp2040 board to try.
I will get in touch with pimoroni today.

Thanks for your time and help.

Cheers

Dave