I’m trying to use the VeX 393 motors with encoders, but these seem to have been designed to work mainly with the cortex, and I haven’t seen any documentation to help me figure out how to get them to communicate with generic devices.
Specifically, I’d like to hook them up to a raspberry pi. I don’t know which of the two data lines are SDA and SCL, and I haven’t managed an i2c read/write, since nothing’s responding at 0x60.
Is there a chance that there’s anything outside the norm I’d need to do to communicate with the encoders? Any history of someone not using the cortex to talk to these? Thanks!
I should add that you will not need the low level bit bang I2C code that was needed on the VEXpro. I did a quick google for I2C on the Pi and it seems lots of others have posted Pi specific examples for other sensors, for example, this site may be a good starting place.
Looking at the 4 Wire Cables that came with my Motor Encoders, and using the Pin Outs for the Cortex, I made a Diagram for the Motor Encoders.
4 Wire Cable is White, Yellow, Red, and Black.
Cortex Color Encoder
=============================================
DATA White DATA
CLOCK Yellow CLOCK
+5 VDC Red +5 VDC
GROUND Black GROUND
Since all the Motor Encoders should be Identical, and can be directly connected to the Cortex, ALL their Pin Outs should be Identical. Since the Cable Crosses Over, the two Connectors on the Motor Encoders will be Pinned the Opposite Direction.
[ATTACH]7098[/ATTACH]
One thing still confuses me, though. I’m using i2ctools to scan addresses of connected i2c devices, and I come up with nothing when I should be at least getting a minimal response on 0x60.
I’m still fairly new to this kind of thing, so I’m not sure which parts of the code posted in the main i2c thread are relevant. I assumed I could just send a read command or a write command on the relevant i2c lines and everything would just work - do I need specific drivers instead?
You don’t need specific drivers, the low level code that I wrote for the VEXpro would not be needed (i2c.c, i2c.h). Use the other code as a guideline, your calls to read and write bytes (or buffers) on the Pi will be different.
The logic analyser trace shows that the IME did not respond with an ACK to the address which was sent. As i2cdetect did not find the IME that’s not surprising so get i2cdetect working first. Is the IME orange led on? Are you connected to the input side of the IME, this is the input with pins, the lower input on MarkO’s picture?
There is a small chance that you need to use address 0x30 (0x60 >> 1). The i2c address is 7 bits, some code assumes that it is packed in the upper 7 bits of an 8 bit byte so all that has to be done for reading is to logical or with 0x01, other code thinks it is in the lower 7 bits and has to be shifted first. i2cdetect should help with this, it is most likely 0x60 but if i2cdetect shows a device on 0x30 then that is what is happening.
Where did you monitor the i2c lines for the analyzer trace you posted?
Ah, I figured out the problem! I had the encoder logic grounded to the same ground as the motors. No wonder.
Yup. I’m using two encoders on two motors, and both orange lights are on.
Yup.
You’re right - the screenshot I posted on the logic analyzer was actually at 0x30 (I tried multiple addresses, and that one matched 0x60). I showed 0x60, but tried both.
They were on the RPi outputs, not the encoder inputs. That would’ve shown my problem!
I have been wondering lately how well a Raspberry Pi works with mechanical applications such as robots. I know they were made to teach students how to write computer programs with a Linux system. How do you like it so far? Ive been thinking of getting one lately. I know you can program motors and encoders with an Arduino and its pretty straight forward.
The Ras Pi GPIO is 3.3V, the I2C lines are pulled up to 3.3V by 1.8K resistors. The IME and cortex are using 5V IO, this may be an issue. We don’t have a schematic for the IME but do know that it uses a STM8S103F3 processor. The IO pin data for this device says minimum threshold for logic high is 0.7xVdd which (with no other buffering) would mean that it needs 3.5V to see logic high. The processor can run with voltage down to 2.95V so you may find that the IME will work with a 3.3V supply rather than a 5V supply, without a schematic it’s impossible to know. I have a RasPi but was never that impressed with it, perhaps next week I will hook it up to an IME and see if I can get it to work.