Using encoders without Cortex

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!

Yes, see this thread, there’s some code attached to post #7.

https://vexforum.com/t/vexpro-arm9-i2c-support/22078/1

I’ve controlled them from other micro-controllers as well, it’s pretty straightforward.

The Wiki Page for “Intergrated Motor Encoders for 2-Wire Motors” has some very helpful information, such as Register Descriptions…

The Pin Out is Identical to the Cortex, since the Cable is ( Correction!! Crossed Over ). That is found on the Cortex Wiki Page.

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]
I2C_Motor_Encoder_01.jpg

You guys are fantastic.

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?

Here’s what I’ve done:

Scanning i2c devices:

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

$i2cset -y 1 0x60 0x4D 0x20 b

Which returns: Error: Write Failed!

I’ve also attached exactly what happens to the lines when sending that i2cset command, if that helps.
i2c-RPi-Vex-Encoders-Error.jpg

Yes, you should.

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.

Actually, that was a false victory. i2cdetect only works intermittantly:

pi@phobos ~$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- 61 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@phobos ~$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@phobos ~$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

Does that seem to imply something electrical, maybe?

I’ll let you know when this is done =p

It seems fairly simple. Certainly more understandable than ATMegas, but there’s always a tradeoff whenever you head to higher levels of abstraction.

We’re also going to be using ROS in our project - I’d recommend taking a look at that.

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.

Got it. Solidly, this time.

pi@phobos ~$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

You were right - supplying it with 3.3v instead of 5v allowed it to read the 3.3v logic from the RPi.

Is the information about the specific chips the IME uses publicly available?

I tried editing the Wiki page on the IME, but there seems to be a problem with my session data. If anyone feels inclined, please copy/paste this to the bottom of https://vexforum.com/wiki/index.php?title=Intergrated_Motor_Encoders:

Have you seen this post here?

https://vexforum.com/t/vex-i2c-integrated-motor-encoder-device-spec/20600/1

Cheers Kb

The datasheet for the processor is here.
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00226640.pdf

When the IMEs first came out I was going to reverse engineer a schematic but never got around to it.

I posted pics of the PCB in a 269 IME here.
https://vexforum.com/showpost.php?p=254839&postcount=4

You can see the micro-controller, U1 near the top. Circuit is pretty simple.

here is a great library for interfacing with the encoders. i use it for all my microcontroller projects

This has not been done, so I did it Now… ( Been a while since I edited the Wiki… :wink: )