Camera interfacing using I2C

OpenMV related project discussion.
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Camera interfacing using I2C

Postby ahamza123 » Fri Dec 02, 2016 5:28 pm

I have a telosb platform. It consists of MSP430 micro controller and CC2420 radio. I want to send a snapshot from OpenMV to telosb using I2C and then transmit wirelessly to another telosb. The problem is that the buffer size of MSP430 is 250 bytes and the max transfer rate is 250 kbps. Any help will be appreciated.
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Fri Dec 02, 2016 11:16 pm

Hi, sorry for not answering this sooner. I just saw this.

So, first, is it possible to use async serial or spi? If not, then you can use I2C but your OpenMV Cam will have to be the master device.

As for the buffer size. That isn't really a concern. We can transmit the image in small chunks. Do you need help with how to go about this in particular? You basically just compress the image and then use the array index functionality to send a few jpeg bytes at a time. You'll be basically transmitting a byte array.
Nyamekye,
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Re: Camera interfacing using I2C

Postby ahamza123 » Sat Dec 03, 2016 5:42 am

SPI is available but the problem is that I kind of need to solder a wire with an IC and I am afraid that I might not burn that IC.
The MSP430 controller can only be used with Master mode only so Can I can use I2C Multi Master mode ?

Yes! I was looking for help to send a few jpeg bytes at a time. Help regarding this would be really appreciated.
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Re: Camera interfacing using I2C

Postby ahamza123 » Mon Dec 05, 2016 6:03 am

I know you are busy in website development and documentation so this is just a reminder.
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Mon Dec 05, 2016 10:14 am

Oh, yeah, I totally forgot about this. I'll do this tonight.
Nyamekye,
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Mon Dec 05, 2016 9:38 pm

Hi, I can't get to this tonight. Something came up for me.

Um, so, did you see this? It's a good example on how to transmit a JPEG compressed image via SPI: viewtopic.php?f=6&t=170#p909.

MicroPython has the rest of the docs: http://docs.micropython.org/en/latest/w ... e.I2C.html.
Nyamekye,
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Re: Camera interfacing using I2C

Postby ahamza123 » Tue Dec 06, 2016 2:55 am

No Problem! I am also not in a hurry, meanwhile I will look into the docs and SPI code.
Thanks again for all the help.
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Re: Camera interfacing using I2C

Postby ahamza123 » Sat Dec 10, 2016 6:42 am

Is there any possibly of using OpenMV as I2C Slave? if by installing new drivers for OpenMV I2C slave? Also do send me the documentation for transferring the image byte by byte.
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Sat Dec 10, 2016 11:36 am

Hi, I'm going to work on this today. As for I2C slave. We use MicroPython's device drivers. If they don't support it we don't either. That said, if you want to change the firmware then you can add the feature. But, that's somewhat hard.
Nyamekye,
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Sun Dec 11, 2016 7:03 pm

Okay, I finally did it:

I've attached two scripts. One makes the OpenMV Cam into a master module that reads data from the slave device. That's how I tested this all out. The second is the slave script which is what you want. The slave script send images out of the camera.

I forgot about your requirement that the I2C buffer is only 256 bytes. I trust you can modify the code to deal with that issue? You just have to split the massive image read into multiple parts. Each part being 256 bytes of the image. I don't think our image methods support accessing images via slices so you'll have to transfer the image data to the temporary byte array I think using "data = bytearray(img)" so that you can slice the data up.

Let me know if you're having trouble.

We don't have a way in our library to turn bytes back into an image so that's why that's not done for you in the master script to see what the slave sees. We'll have to add that to the firmware.

*Make sure to attach pull ups on the I2C lines*
Attachments
is2_slave.py
(1.38 KiB) Downloaded 149 times
is2_master.py
(1.27 KiB) Downloaded 103 times
IMG_20161211_185532611_HDR.jpg
IMG_20161211_185532611_HDR.jpg (235.2 KiB) Viewed 3794 times
IMG_20161211_185518427_HDR.jpg
IMG_20161211_185518427_HDR.jpg (242.99 KiB) Viewed 3794 times
IMG_20161211_185514746.jpg
IMG_20161211_185514746.jpg (182.7 KiB) Viewed 3794 times
IMG_20161211_185512281.jpg
IMG_20161211_185512281.jpg (210.28 KiB) Viewed 3794 times
Nyamekye,
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Sun Dec 11, 2016 7:08 pm

Actually, it looks like images support being sliced so just array access for the bytes you need. i.e img[0:250] to get the first 250 bytes from index 0, etc.
Nyamekye,
User avatar
kwagyeman
Posts: 2037
Joined: Sun May 24, 2015 2:10 pm

Re: Camera interfacing using I2C

Postby kwagyeman » Sun Dec 11, 2016 7:12 pm

K, I'm wrong about that. You have to do this to transfer the data:

Code: Select all

img = sensor.snapshot().compressed()
b = bytearray(250)
for i in range(250):
    b[i] = img[i]


So, basically just transfer over the bytes you need into a new array manually. Just do that for all the bytes until the last ones.

Note that the data in the image is JPEG data. So, don't try to do anything with it until its delivered to a system that can JPEG uncompress the data.
Nyamekye,
ahamza123
Posts: 6
Joined: Fri Dec 02, 2016 5:15 pm

Re: Camera interfacing using I2C

Postby ahamza123 » Fri Dec 16, 2016 9:16 am

Oh, I just looked at the files you sent. Thank you soo much for the help. I am extremely sorry for thanking you very late. I am busy in the exams, might disturb you in near future. Thanks again.

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest