User avatar
jojopi
Posts: 3353
Joined: Tue Oct 11, 2011 8:38 pm

Re: GPIO Programming Question

Tue Feb 14, 2012 9:44 am

hzrnbgy said:


The only problem is that the typical Arduino mcu (AVR atmega) runs at 5V but the RPi at 3V3. You would need a level converter.


The ATmega168/328/1280/2560/32u4 used on the Arduino boards all support 3.3V supply.  It is the boards that limit you to running them at 5V.

acmbc68
Posts: 11
Joined: Thu Jan 26, 2012 2:28 pm

Re: GPIO Programming Question

Tue Feb 14, 2012 7:10 pm

Roli - If you are still on the RPi+MCU track, and one Arduino won't cut it, have a look at the Pinguino (www.pinguino.cc) or the Maple

Physically Arduino clones, same pinouts, same language and environment, but they are 32 bit MCUs at much higher speeds and should easily cut it for what you need.

Caveat: Not all Arduino libraries are ported to these....

roli said:


Well I did a bit of thinking. I could still use the Arduino as an IO bridge (use it to connect to actual hardware and sensors) but do all the processing on the RPi. This is one option but I don't realy like it since I still need an Atmega chip with arduino bootloader, USB to serial adapter (or an FTDI chip) and special code written for the arduino. But I don't see any other way since I need an option of generating IR pulses (microsecond acuracy is a must) and responding to interrupts at the same time. Arduino can handle this quite nicely. But I needed another arduino that controlled the character display, worked with relays, received commands from an IR remote, did al the processing and sent the information to the computer. It is interesting that a device with a 16MHz clock was more than capable of doing that, while a much faster device like RPi isn't.


roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Tue Feb 14, 2012 7:38 pm

Interesting. My problem with arduinos ins't realy the speed, it is more a problem of memory and IO pins. The Atmega 328 helps a lot since it has more memory and more RAM. The Arduino Mega with ATmega2560 is a lot better choice. Sadly it is only available in SMD package and I have no experience in soldering those. And even if I could solder it myself, there is still a problem of flashing the bootloader. For the Atmega 8/168/328 you could use the Arduino board itself to flash a blank chip so there was no need for external programmer.

And these clones are nice but as you said not all libraries have been ported and they still have similiar problems as the Arduino.

lb
Posts: 276
Joined: Sat Jan 28, 2012 8:07 pm

Re: GPIO Programming Question

Wed Feb 15, 2012 10:08 am

I don't understand why you guys are so fixed on Arduino. Just use a plain AVR (or PIC, or MSP430). There's not much circuitry required to get it going and to program it.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 11:06 am

Seconded. If you're going to be building stuff anyway, you may as well get a bit of veroboard and an AVRMega64. 40 DIL pins of I/O goodness at a nice compatible 3.3V.

Programmers are very cheap now, even without going for the £2 parallel-port-and-configure-it-yourself cards from eBay. (Probably good to give those a miss if you're mixing voltage levels.)

The minimum components necessary are:

two resistors

two capacitors (one optional)

one diode

one switch (for reset, optional)

one 6- or 10-way pin header for programming

one resonator

one DIL socket (optional, recommended)

one AVR processor

Enough Veroboard to hold them all.

You could program in a bootloader and then program it in serial direct from the RPi's GPIO lines, but it's just as easy to do it with the programmer every time.

roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 12:08 pm

I think you didn't understand me properly. I am using ATmegas with the Arduino Bootloader, but I am not using the actual Arduino boards – except for the prototyping. When I know what I want, I just simply draw myself a PCB and I am done. Much better than veroboard. And you need 4 capacitors, crystal and a socket. I use the arduino board to programm the chip and that is it.

While I don't want arduino hardware, I do realy like the programming language.

But I see that you can run the Arduino bootloader on the Atmega 644 so I might use it for the next project. But I will need to get myself an AVR programmer. Any ideas if I can build myself one on the cheap or where I can get a cheap version?

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 12:41 pm

If I understand correctly, when the bootloader is installed, the Arduino is programmed from the serial port. So if you power it from 3.3V, it is compatible with the serial port on the RaspPi GPIO. If you wanted to program it from a desktop PC, you would need RS232  level-changing stuff or a USB-serial board that had a 3.3V interface.

When I bought mine, eBay sellers had programmer boards that connected to a standard parallel port, but the pins they used were non-standard. That just meant your programmer app needed to be configurable.

Now I look again, they seem to have gone over to USB. Here's one that should work OK for £3: http://www.ebay.co.uk/itm/USBA.....1c2061b9f7 There are links on there to the open-source design that it is based on. (And where you can buy a kit for under €20.)

The official Atmel programmer is only £26: http://uk.rs-online.com/web/p/.....r/6962563/

I've no experience with the Arduino, but I've built up a board with a mega64 and a ten-pin header. It works fine.

roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 1:18 pm

I have found something much better:

http://arduino.cc/en/Tutorial/ArduinoISP

This is something new. Before you could burn the bootloader with the arduino too, but it needed a little more wiring and wasn't that user friendly - and it only worked with the Atmega 8/168 - well they did add a 328 later (I think).

This is a relaly good find.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 1:49 pm

Rather than use two Arduino boards, that should work if you wire to a standard 10 or 6 pin socket.

Mind you, you'll be doing well to find a 10-pin IDC socket for under £3, and you certainly couldn't do it if you added in your time.

roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 2:48 pm

Or I can simply put it in a breadboard and add those 5 wires to it and I am done. I can then use it for prototyping on a breadboard and when I am finished with the design relocate it to a PCB. Fast, simple and cheap.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO Programming Question

Wed Feb 15, 2012 10:12 pm

Just a remark. Gertboard V2 (Which went out last Monday) has the ATMega328 and the 328-UART pins are adjacent to the Raspberry UART pins. Just need two jumpers to connect them up. I did that as the Arduino board also talks to the master CPU using the UART. Also has the JTAGIC MarkII 6-pin programming header. In contrast to the Arduino boards it runs all from 3V3. Cut out from schematic below.


roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Thu Feb 16, 2012 11:37 am

Interesting. This could be useful for some things but there is one major problem with this - 3.3V. I can see a few problems with this. And the fact that it is in the SMD package.

But there are never too many IO pins so this is realy good.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO Programming Question

Thu Feb 16, 2012 1:37 pm

roli said:


Interesting. This could be useful for some things but there is one major problem with this - 3.3V. I can see a few problems with this. And the fact that it is in the SMD package.

But there are never too many IO pins so this is realy good.



There is no simple way around the 3V3. You need level translators which are a pain in the B.tt.  Where did you get the idea from that it is SMD? It is 28 pins DIP.

Chris.Rowland
Posts: 239
Joined: Thu Jan 12, 2012 5:45 pm

Re: GPIO Programming Question

Thu Feb 16, 2012 6:21 pm

Is 3.3V a problem? From what I can see most peripherals use 3.3V now.  My most recent foray into electronics is a PicAxe measuring the compass heading and sending it using a 433Mhz transmitter and it's all working fine with 2 AA batteries.

Chris

roli
Posts: 13
Joined: Mon Feb 13, 2012 12:54 pm
Contact: Website

Re: GPIO Programming Question

Thu Feb 16, 2012 9:13 pm


Where did you get the idea from that it is SMD? It is 28 pins DIP.



From the schematic. It looks like an SMD chip (sort off). I never saw a DIP that has pins on all four corners, so I thought it was an SMD. But DIP is great.

3.3V isn't much of a problem but I have a custom designed emitter PCB and it needs 5V. I would have to check if I can simply switch resistors or something else. And I think that a 5V is better when dealing with longer cables (as with home automation).

But as allways - I will figure something out.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO Programming Question

Thu Feb 16, 2012 10:23 pm


From the schematic. It looks like an SMD chip (sort off). I never saw a DIP that has pins on all four corners, so I thought it was an SMD. But DIP is great.


Ah! that explains it. The schematic symbol is no representation of the actual package. In fact I made that symbol myself and I always bring the power pins out with VCC at the top and GND at the bottom.

User avatar
csoutreach
Posts: 32
Joined: Mon Nov 28, 2011 1:06 pm
Contact: Website

Re: GPIO Programming Question

Thu Feb 16, 2012 11:06 pm

davidgoodenough said:


Not a problem, linux exports gpio pins as files under /sys/class/gpio, you can open them using normal file IO from Java and away you go.



We're trying to make it easy to do just this sort of thing for anyone. We're in the process of trying to come up with an I/O interfacing set of API s that can be used across languages and across add on boards (consistently) as part of http://piface.openlx.org.uk/mi.....ware-57029. Basic idea is some interprocess call to a hardware supervisor which also does visualisation and error checking.

Before anyone says it, we'd like to point out we're not trying to go for low latency control as we're targeting the same people Raspberry Pi was designed for.

Anyone want to lend a hand, or suggest thoughts on the architecture? We need helpers to write parsers, gtkmm and device driver glue.
http://piface.openlx.org.uk/ Raspberry Pi IO Interface Board

User avatar
fulburncams
Posts: 70
Joined: Wed Nov 30, 2011 8:29 pm

Re: GPIO Programming Question

Fri Feb 17, 2012 5:17 pm

Hi

With regards to the PWM aspect,  is the PWM available as specified in the BCM2835 Section 9 alternate GPIO Functions and if so,  from the spec it looks as though this is a hardware PWM ( apart from defining mark/space (N/M) ratio, Frequency, clock source, starting and stop etc) so not dependent on what else Linux is doing.  Sorry If I have misunderstood.

Cheers

Steve

kkman20xx
Posts: 14
Joined: Mon Mar 05, 2012 3:47 pm

Re: GPIO Programming Question

Tue Mar 06, 2012 10:11 pm

From what I can see in the BCM2835 there are only 2 PWM channels which is not enough for most people.  However you can get a servo controller with a UART interface which is cheap enough.

The Arduino is a mature platform with many libraries support many hardware.  It would be much easier to use than custom your own MCU. I would mostly prefer the Pro Mini which is small enough to be included in a circuit.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: GPIO Programming Question

Tue Mar 06, 2012 10:22 pm

Interesting that nobody spotted that the 6-pin header in the picture in post 36 above is wrong.

Does anybody know why the Arduina has a diode to VCC at the reset pin? I dutifully copied it just to be sure. All I could think of is to protect againt high voltage spikes from the Atmel debugger.

I know you need a diode if you have an R-C circuit on the debug pin but that is not the case here. Or maybe the Arduino designer did not know enough about electronics and copied it from an RC design, then removed the capacitor as it interfered with the debug signal, but did not know what the diode was for and left it in place.

kkman20xx
Posts: 14
Joined: Mon Mar 05, 2012 3:47 pm

Re: GPIO Programming Question

Tue Mar 06, 2012 11:55 pm

Not sure why some verion has it and some don't. The rev3 Uno has it but not the mega2560.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4257
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: GPIO Programming Question

Wed Mar 07, 2012 7:37 am

The hardware application note describes the diode:

AVR042 says:


Connecting the RESET so that it is possible to enter both high-voltage  programming and ordinary low level reset can be achieved by applying a  pull-up resistor to the RESET line. This pull-up resistor makes sure that  reset does not go low unintended. The pull-up resistor can in theory be of  any size, but if the AVR should be programmed from e.g. STK500/AVRISP  the pull-up should not be so strong that the programmer cannot activate  RESET by draw the RESET line low. The recommended pull-up resistor is  4.7kOhm or larger when using STK500 for programming. For debugWIRE to  function properly, the pull-up must not be smaller than 10kOhm.

To protect the RESET line further from noise, it is an advantage to connect a  capacitor from the RESET pin to ground. This is not directly required  since  the AVR internally have a low-pass filter to eliminate spikes and  noise that  could cause reset. Applying an extra capacitor is thus an  additional  protection. However, note that this capacitor cannot be present if  debugWIRE is used.

If not using High Voltage Programming it is recommended to add an ESD   protecting diode from RESET to Vcc, since this is not internally provided   due to High Voltage Programming. The components should be located   physically close to the RESET pin of the AVR. 


magingax
Posts: 2
Joined: Wed May 02, 2012 11:11 pm

Re: GPIO Programming Question

Fri May 04, 2012 10:37 pm

My question is simple Is it possible to generate PWM via GPIO ??
I will control 4 motor"s speed with RPi
purse time 20ms
maxspeed purse 2ms
minspeed purse 1ms
I heard it can be done just setting string on GPIO
please show me some sample code

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13368
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: GPIO Programming Question

Fri May 04, 2012 10:40 pm

As far as I remember, the gert board did this, and has example code, perhaps you can find it on the wiki.

User avatar
gordon@drogon.net
Posts: 2022
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website Twitter

Re: GPIO Programming Question

Sat May 05, 2012 11:11 pm

magingax said:


My question is simple Is it possible to generate PWM via GPIO ??
I will control 4 motor"s speed with RPi
purse time 20ms
maxspeed purse 2ms
minspeed purse 1ms
I heard it can be done just setting string on GPIO
please show me some sample code



Without going any hardware hacking, the GPIO has one PWM output. So with that, you'll only control one motor speed. Even if you do some hardware hacking, it only has 2 PWMs anyway.

And sadly, I can't find the proper documentation for setting the clock frequencys, etc. I've just looked at Gerts code so-far. The BCM ARM peripherals manual seems to be lacking the clock settings (or I've just missed them).

So for 4 motors your really looking at doing in other ways - e.g. connect up an Arduino and use it's PWM outputs, and send high-level commands to it from the Pi.

See https://projects.drogon.net/raspberry-pi/wiringpi/ for some stuff to drive the PWM output (and other GPIO pins)

Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “General discussion”