User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

How to get Arduino working with the Raspberry Pi...

Mon Jan 07, 2013 6:24 pm

Hello! This forum post is going to be the C++ code for my newest Raspberry Pi tutorial all about how to use the Arduino with the Raspberry Pi... Give it a look here:

http://www.youtube.com/watch?v=F-te4qkbh28

Onto the code:

To install the IDE first do:

Code: Select all

sudo apt-get update 
And then:

Code: Select all

sudo apt-get install arduino

Now open the Arduino IDE and here is the code!:

Code: Select all

//This simple Program lights up the OnBoard and external LED on Pin 13
// Made by The Raspberry Pi Guy ©

int ledPin = 13;

void setup()
{
  //initialize pins as outputs
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}
Hope you enjoy my videos!

The Raspberry Pi Guy :ugeek:
Last edited by raspberrypiguy1 on Mon Apr 08, 2013 4:32 pm, edited 2 times in total.
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

condew
Posts: 3
Joined: Thu Apr 04, 2013 4:47 pm

Re: How to get Arduino working with the Raspberry Pi...

Thu Apr 04, 2013 4:54 pm

What distribution are you running? I'm running Raspbian Wheezy and "sudo apt-get install arduino" spit out a number of not found error messages. I suspect you are running "soft float" Raspbian Wheezy as I think Arduino uses java and the only Java I've read about only runs under "soft float".

User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 11:50 am

Nope I'm using normal Raspbian Wheezy... Try

Code: Select all

sudo apt-get update
first, and then run the commands in my tutorial!

The Raspberry Pi Guy
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 1:37 pm

First love your videos very nicely done, but if you get time maybe you could consider make a video on how simple running code bare metal (without a OS) on the pi is.
Example the code you wrote above is almost the same as the code to do the same for the pi bare metal.
Example:

Code: Select all

;*
;* Blink
;*
;* Basic raspberry pi example. Turns on an LED for one second,
;* then off for one second and so on.. we use the built in green
;* OK LED, gpio number 16 (see page 102 BCM2835 PDF)to keep things
;* simple.
;*
include 'DexBasic\DexBasic.inc'
                                                   ;
pinMode  GPIO16, OUTPUT                            ;
                                                   ;
LetsLoop:                                          ;
                                                   ;
digitalWrite  GPIO16, HIGH                         ;
delayMicroseconds  1000000                         ;
digitalWrite  GPIO16, LOW                          ;
delayMicroseconds  1000000                         ;
                                                   ;
goto  LetsLoop                                     ;
                                                   ;
align 4                                            ;
ProgramSize:                                       ;
ScreenBuffer:                                      ;       
This flash the OK led on and off once a second
If you need more info see here: http://www.dex-os.com/DexBasic/DexBasic.htm

You can do stuff like this in about 10 lines of code
http://www.youtube.com/watch?v=Hc-5epQTul8
Batteries not included, Some assembly required.

User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 1:58 pm

Of course! I will definitely be looking at doing a tutorial for bare metal... However I am not completely sure about all the facts... You say its like running the Pi without an OS... What do you mean by this? Could you please explain to me a little about bare metal, because I am proud to say that I am a bare metal noob!

Thanks

The Raspberry Pi Guy
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 7:58 pm

raspberrypiguy1 wrote:Of course! I will definitely be looking at doing a tutorial for bare metal... However I am not completely sure about all the facts... You say its like running the Pi without an OS... What do you mean by this? Could you please explain to me a little about bare metal, because I am proud to say that I am a bare metal noob!

Thanks

The Raspberry Pi Guy
Sure i mean it as no OS like linux or riscos, so you are writing directly to the hardware, similar to how a ardinuo works.
This means you have full control and can write/read GPIO by using the right address and you can boot in1-2 seconds and just turn your pi off by just turning the power off.
But it also mean you do not have the driver for things like usb, network.

There is support for usb keyboards , but only works with about 40% of them.
So in short your coding your own mini OS.
Hope this helps.
Batteries not included, Some assembly required.

User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 8:10 pm

DexOS wrote:
raspberrypiguy1 wrote:Of course! I will definitely be looking at doing a tutorial for bare metal... However I am not completely sure about all the facts... You say its like running the Pi without an OS... What do you mean by this? Could you please explain to me a little about bare metal, because I am proud to say that I am a bare metal noob!

Thanks

The Raspberry Pi Guy
Sure i mean it as no OS like linux or riscos, so you are writing directly to the hardware, similar to how a ardinuo works.
This means you have full control and can write/read GPIO by using the right address and you can boot in1-2 seconds and just turn your pi off by just turning the power off.
But it also mean you do not have the driver for things like usb, network.

There is support for usb keyboards , but only works with about 40% of them.
So in short your coding your own mini OS.
Hope this helps.
That sounds very interesting... So, do you build your own OS layer by layer then? And is it in Assembly Language?

Thanks

The Raspberry Pi Guy
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: How to get Arduino working with the Raspberry Pi...

Mon Apr 08, 2013 11:52 pm

Yes its in assembly, but i use the assembly macros to make a basic like language to make it easier for beginners to understand.
Batteries not included, Some assembly required.

Return to “Automation, sensing and robotics”