barbeker
Posts: 12
Joined: Thu Sep 10, 2015 7:37 am

convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 7:18 am

hi guys, i'm new to RPI and i would appropriate it if you could help me to get started.
i need to build a serial communication system, and the first stage is to be able to take a file (lets say a jpg pic) convert it into a stream of bits and write it to a gpio pin. since speed is a crucial requirement, i probably gonna use C language.

any idea on how to start?

thank you.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26659
Joined: Sat Jul 30, 2011 7:41 pm

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 10:05 am

Ther are a couple of libraries that wil be of use, libPNG and libJPEG, both allow you to load an image in to RAM. Fromt here you can simplyt read throught he data and ping the GPIO up and down as necessary. There is also a library for GPIO that will help with that bit.

However, the speed of the GPIO is not particularly high, so you don;t have to use C, Python would probably be fast enough.

But, depending on your use case, there may be better options than GPIO. Why do you need to do it like that?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

barbeker
Posts: 12
Joined: Thu Sep 10, 2015 7:37 am

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 11:07 am

first of all, thank you very much.

acording to http://hackaday.com/2015/03/27/the-pi-2 ... ster-gpio/ toggling between zero and one could go up to 42MHZ using C and up to 70KHz using python. i need to get a transsmition rate larger then 1 Mbps, so using python isn't really un option.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 11:13 am

Have a look into lrzsz :

Code: Select all

sudo apt-get install lrzsz
man sz

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

barbeker
Posts: 12
Joined: Thu Sep 10, 2015 7:37 am

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 12:56 pm

ghans wrote:Have a look into lrzsz :

Code: Select all

sudo apt-get install lrzsz
man sz

ghans

i will thanks. on the mean time any idea on how to write data to gpio in c?

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 1:27 pm

The sensible thing to do would be transmit the data on a serial link as the protocol is widely supported. You could just write the file to /dev/ttyAMA0 which outputs on GPIO 14.

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: convert a pic to bit stream and write it to gpio

Tue Dec 29, 2015 2:21 pm

What is in the other side of the communication ?

Is it another PI or a computer.

The GPIO14 & GPIO15 serial communication could be increase if you change the clock rate

I put 64Mhz for my clock by adding this into the /boot/config.txt

Code: Select all

init_uart_clock=64000000
You could use pppd for communication link. Then it will be a TCP/IP protocol. sftp,ssh, ftp, etc....

If you are interrested about pppd check my link
viewtopic.php?p=826629#p826629

I set the communication baud to 4M baud and I had no problem at all.

Even did a connection like this without any problem. Just need some iproute.

viewtopic.php?p=849657#p849657

Return to “Beginners”