Connecting Picaxe with Pixy (CMUcam5)

LoganArmando

New Member
Hey everyone!

I am doing a project for an international robotics competition and I need to connect my robot's picaxe (40x2) to a Pixy camera. In the Pixy's website they only give instructions on how to connect it to Ardiuno or Raspberry.
In consequence, I searched for the pins of the I/O port in order to connect them to my picaxe.
So I looked for the SDA, SCL, 5V, and GND once I am using I2C communication.
After everything was well connected and functioning well I had to program the picaxe and debug the info coming from the camera. But I didn't know what to code in order to do get that debug right.
I searched for i2c commands which I have already used with a compass and found the differences between i2cfast/i2cslow, i2cbyte/i2cword. Without understanding so well the difference between these I tried all of them and didn't get anything in the debug window.
To get the debug, I needed to find the camera's address, which I found in the Pixymon's application, somewhere in the settings tab. I got it and then wrote this code:

Code:
Main:
i2cslave 0x54, i2cfast, i2cbyte
readi2c 0, (b1)
readi2c 1, (b2)
debug
goto Main
After this I even tried adding more variables, once camera gives up to 10 different informations (position in x, position in y, width, height), and nothing happend.
I never coded a picaxe connected with a camera. And as this is my first time, I would like someone to tell me how I should code to get info.

Thanks for reading this!
 

Rick100

Senior Member
Hello Logan,

Here are 2 threads you should read.
http://www.picaxeforum.co.uk/showthread.php?29248-PIXY-CMUcam5-and-PICAXE-28X2-module
http://www.picaxeforum.co.uk/showthread.php?26245-Camera-Pixy-vision-sensor

They appear to use serial instead of i2c to communicate with the camera, but it's a good starting point. If you stick with i2c , I think you need the hi2csetup command to set the picaxe as i2c master. The address may have to be multiplied by 2 if other Arduino to Picaxe conversions are any indication. It's probably easier to stick with the serial code for early experimenting.

Good luck,
Rick
 
Last edited:

stan74

Senior Member
I'd not heard of pixy cam. I've some RPis and thinking of using an old one for a robot. I notice this camera can recognise moving objects but the robots I build tend to recognise stationary objects :)
 

LoganArmando

New Member
Hello Logan,

Here are 2 threads you should read.
http://www.picaxeforum.co.uk/showthread.php?29248-PIXY-CMUcam5-and-PICAXE-28X2-module
http://www.picaxeforum.co.uk/showthread.php?26245-Camera-Pixy-vision-sensor

They appear to use serial instead of i2c to communicate with the camera, but it's a good starting point. If you stick with i2c , I think you need the hi2csetup command to set the picaxe as i2c master. The address may have to be multiplied by 2 if other Arduino to Picaxe conversions are any indication. It's probably easier to stick with the serial code for early experimenting.

Good luck,
Rick
Hello Rick,

I've already tried using serial communication, but it was unsuccessful too. Now I have the pixy connected to the Picaxe and my problem is just the code.
You said I could use the hi2csetup command, which I am going to try. But I didn't understand the address part. To get the address I just went to the camera's computer application and in a settings tab there was i2c address which was something like "0x54". So maybe the address is wrong... So what should I do, besides trying the command?
 

AllyCat

Senior Member
Hi,

For the hi2csetup, note that the PICaxe is being used as a master, not a slave, and it's generally safer to start with i2cslow and try increasing to fast when the interface is working correctly.

I2C addresses have only 7 bits, with the eighth (LSB) used as a read/write flag. If the address is quoted as an odd number, then you know it must be multiplied by 2 to use with a PICaxe. If it's even, then you may have to try both (or read the data sheet carefully) but it's probable that you need to multiply it by 2 (e.g. to $A8 ) particularly if converting from Arduino code.

Cheers, Alan.
 

Rick100

Senior Member
Hello Logan,

The only thing I would add to Alan's answers are a couple of example lines.

hi2csetup i2cmaster, $A8, i2cslow, i2cbyte

should set up the i2c communications and

hi2cin (b0)

should read a byte from the device. If you want to use i2c you'll have to receive bytes and look for the $AA followed by a $55 or $56. Then you can receive the data.

Quoting from the porting guide at http://cmucam.org/projects/cmucam5/wiki/Porting_Guide

"Whether you're using SPI, I2C or UART serial, the protocol is exactly the same."

In that case Hippy's code at
http://www.picaxeforum.co.uk/showthread.php?29248-PIXY-CMUcam5-and-PICAXE-28X2-module&p=301765&viewfull=1#post301765
is a great place to start. It shows how to read the bytes into Picaxe word variables.

I would advise you again to try the serial port since the code is already written. You should be able to leave the i2c lines hooked up and run a jumper from a Picaxe pin 26 to pin 4 of the Pixy. Just change the lines in the link above from
#Picaxe 28X2 to #Picaxe 40X2
and
Symbol RX_PIN = C.3 to Symbol RX_PIN = C.7

I chose C.7 because you might want to change to hardware serin in the future. You'll have to set the Pixy to use the Uart and 9600 baud in you PixyMon software.

Good luck,
Rick
 

hippy

Ex-Staff (retired)
I would advise you again to try the serial port since the code is already written.
I would agree with that, if for no other reason that it will prove the camera, PICAXE and everything else is working. If it doesn't it should be easier to fix.

Once something is working reliably one can stick with that, or move to I2C or SPI if still desired. Serial is still a fall-back just to prove the camera is still working even if I2C or SPI doesn't seem to be working.
 

LoganArmando

New Member
Hi,

For the hi2csetup, note that the PICaxe is being used as a master, not a slave, and it's generally safer to start with i2cslow and try increasing to fast when the interface is working correctly.

I2C addresses have only 7 bits, with the eighth (LSB) used as a read/write flag. If the address is quoted as an odd number, then you know it must be multiplied by 2 to use with a PICaxe. If it's even, then you may have to try both (or read the data sheet carefully) but it's probable that you need to multiply it by 2 (e.g. to $A8 ) particularly if converting from Arduino code.

Cheers, Alan.
Hey!

Thanks, I will try to do that.
But I just don't understand the hex number part. I've never dealt with that and I don't know how to multiply what I got by 2, in order to get convert 0x54 to something like $A8.
 

LoganArmando

New Member
Hello Logan,

The only thing I would add to Alan's answers are a couple of example lines.

hi2csetup i2cmaster, $A8, i2cslow, i2cbyte

should set up the i2c communications and

hi2cin (b0)

should read a byte from the device. If you want to use i2c you'll have to receive bytes and look for the $AA followed by a $55 or $56. Then you can receive the data.

Quoting from the porting guide at http://cmucam.org/projects/cmucam5/wiki/Porting_Guide

"Whether you're using SPI, I2C or UART serial, the protocol is exactly the same."

In that case Hippy's code at
http://www.picaxeforum.co.uk/showthread.php?29248-PIXY-CMUcam5-and-PICAXE-28X2-module&p=301765&viewfull=1#post301765
is a great place to start. It shows how to read the bytes into Picaxe word variables.

I would advise you again to try the serial port since the code is already written. You should be able to leave the i2c lines hooked up and run a jumper from a Picaxe pin 26 to pin 4 of the Pixy. Just change the lines in the link above from
#Picaxe 28X2 to #Picaxe 40X2
and
Symbol RX_PIN = C.3 to Symbol RX_PIN = C.7

I chose C.7 because you might want to change to hardware serin in the future. You'll have to set the Pixy to use the Uart and 9600 baud in you PixyMon software.

Good luck,
Rick
Hey!

I'll try to code what you guys suggested. If I don't get anything, then I will try again with serial by using Hippy's code, although I don't understand it completly.
 

cravenhaven

Senior Member
Hey!

Thanks, I will try to do that.
But I just don't understand the hex number part. I've never dealt with that and I don't know how to multiply what I got by 2, in order to get convert 0x54 to something like $A8.
Use the windows calculator in Programmer mode. Select hex as the number system, then multiply 54 by 2.
 
Top