Arduino Forum

Using Arduino => Microcontrollers => Topic started by: siyete on Dec 24, 2012, 07:08 am

Title: Connecting Arduino to PIC
Post by: siyete on Dec 24, 2012, 07:08 am
hi im doing this project FYI: im a beginner at programming..
i want to use the digital output of arduino and connect it to a pic16f877a pin..

so arduino(output) to pic16f877a(input)

i tried connecting it to my pic and it doesnt do anything..
i tried connecting a resistor and led to the connecting wires so that i will know if the connections are good..
and the led lights up, so arduino is sending a signal but the pic doesnt do anything..
what am i doing wrong?..
Title: Re: Connecting Arduino to PIC
Post by: Osgeld on Dec 24, 2012, 08:06 am
is the pic expecting input where your hooking up to? its a software driven device like the arduino
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 24, 2012, 09:18 am
yes i configured all PORTA to input, here is part of my code for the pic:

Code: [Select]

ALL_DIGITAL = True
PORTB_PULLUPS = On

TRISA  = %111111
TRISB  = %00000000
TRISC  = %00000000
TRISD  = %00000000
TRISE  = %111

----------Arduino Controls----------
arduino:

If PORTA.2 = 1  And PORTA.3 = 1 Then
GoTo Forward_Slow
   
ElseIf PORTA.2 = 0  And PORTA.3 = 1 Then
GoTo Left_Slow
 
ElseIf PORTA.2 = 1  And PORTA.3 = 0 Then
GoTo Right_Slow

Else
   If PORTE.0 = 1 And PORTE.1 = 0 Then
   GoTo Grab_Ball
   
   ElseIf PORTE.0 = 0 And PORTE.1 = 1 Then
   GoTo Back_Slow
   
   Else
   GoTo Rotate_Right
   EndIf
EndIf
   
GoTo main

'----------Drive Controls----------
Forward_Slow:
High PORTD.0
Low  PORTD.1
High PORTD.2
Low  PORTD.3
Clear PORTD
GoTo main
     
Right_Slow:
High PORTD.1
High PORTD.2
Clear PORTD
GoTo main

Left_Slow:
High PORTD.0
High PORTD.3
Clear PORTD
GoTo main

Back_Slow:
Low  PORTD.0
High PORTD.1
Low  PORTD.2
High PORTD.3
Clear PORTD
GoTo main

Rotate_Right:
Low  PORTD.0
High PORTD.1
High PORTD.2
Low  PORTD.3
DelayMS 500
Clear PORTD
GoTo main


the led is lighting up, meaning the wiring is good right?.. and i believe the program is also good..
because when i switch the port meant for arduino and replace it with an infrared proximity sensor it does what it is supposed to do..
the proximity sensor also gives high and low signal, same as arduino but why when i plug arduino on the pic it does nothing..
Title: Re: Connecting Arduino to PIC
Post by: mauried on Dec 24, 2012, 11:47 am
Does the 16f887 have some kind of program in it ?
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 24, 2012, 11:58 am
yes the pic16f877a is programmed to receive input
and the arduino is programmed to produce output..
both use digital signal..
Title: Re: Connecting Arduino to PIC
Post by: oric_dan on Dec 24, 2012, 07:09 pm
I'm not famliar with using Basic on a PIC, but the '877A boots up with Port A pins
all set to analog, and need to be changed for use as digital pins. I don't know if
"ALL_DIGITAL = True" actual does this for Port A. In any case, you might try using one
of the Port B or C pins for the input.

Also, there is no indication in your code what the various configuration fuses are set to,
nor what the oscillator setting is. Maybe the compiler takes care of that automatically,
I don't know. Is this a Picaxe, or what?
Title: Re: Connecting Arduino to PIC
Post by: mauried on Dec 25, 2012, 12:02 am
A circuit diagram would help.
The 16F887 code seems to be some kind of combinatorial logic that needs combinations of input pins to do anything.
Are all the pins that are defined as inputs connected to something?
Title: Re: Connecting Arduino to PIC
Post by: dhenry on Dec 25, 2012, 12:22 am
Test the arduino and pic individually to make sure that they behave as expected, then connect them together.

Otherwise, you don't where the problems are.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 26, 2012, 01:17 pm
Quote
I'm not famliar with using Basic on a PIC, but the '877A boots up with Port A pins
all set to analog, and need to be changed for use as digital pins. I don't know if
"ALL_DIGITAL = True" actual does this for Port A. In any case, you might try using one
of the Port B or C pins for the input.

Also, there is no indication in your code what the various configuration fuses are set to,
nor what the oscillator setting is. Maybe the compiler takes care of that automatically,
I don't know. Is this a Picaxe, or what?


those are not my full codes, i just posted parts of the code.. im using proton basic..
im using xtal osc 4mhz, and using "ALL_DIGITAL = True" really changes the pins to digital..

these are my pin configurations:
arduino - pic - purpose
digital 13 - PORTA.3 - Send Signal To PORTD[Output Pin] To Turn Left Motor On/Off
digital 12 - PORTA.2 - Send Signal ToPORTD[Output Pin] Output Pin To TurnRight  Motor On/Off

Quote
A circuit diagram would help.
The 16F887 code seems to be some kind of combinatorial logic that needs combinations of input pins to do anything.
Are all the pins that are defined as inputs connected to something?


yes all the pins are defined as input, its in the codes i posted
TRISA  = %111111, 1 is for input 0 is for output..

im working on doing a circuit diagram,..
its been christmas vacation so ive been busy with family matters..

Quote
Test the arduino and pic individually to make sure that they behave as expected, then connect them together.

Otherwise, you don't where the problems are.

ive doing this right now, ive tested arduino and its working fine..
gonna test my pic16f877a next, but i believe the problem lies on the signal..
im thinking if i should use a switching transistor..

im currently using this wiring: (http://www.winpicprog.co.uk/graphics/sw_example1.gif) but ill try using a 2n3904 transistor: (http://www.winpicprog.co.uk/graphics/tran_example1.gif)


Title: Re: Connecting Arduino to PIC
Post by: P18F4550 on Dec 26, 2012, 04:12 pm
I have a couple of surgestions

Rather than diving head first and writing pages of code, just try a simple program with one switch in and one led out.

Get yourself an 18F452, all 18F's can be programmed with the C18 compiler which is going to be closer to arduino code and therefore make porting code between devices easier, I never liked Proton, it is easy to learn but somewhat limited in functionality and speed, The 16F877 is still a good chip but not supported by C18

Alternativly try a smaller chip like 16F84a with less hardware so less complication, it's easier to upscale later
Title: Re: Connecting Arduino to PIC
Post by: oric_dan on Dec 26, 2012, 07:06 pm
Quote
Rather than diving head first and writing pages of code, just try a simple program with one switch in and one led out.


This is always the proper way to proceed with new programs. Get the basic, simple stuff
working first, and then build around that.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 26, 2012, 08:24 pm

Quote
Rather than diving head first and writing pages of code, just try a simple program with one switch in and one led out.


This is always the proper way to proceed with new programs. Get the basic, simple stuff
working first, and then build around that.


(http://www.winpicprog.co.uk/graphics/sw_example1.gif)(http://www.winpicprog.co.uk/graphics/sw_example2.gif)
just tried it an hour ago, and it doesnt work.. tried both active low and active high..
maybe i really need to have a transistor for it to work.. ill try to drop by local electronic store to get 2n3904..
(http://www.winpicprog.co.uk/graphics/tran_example1.gif)(http://www.winpicprog.co.uk/graphics/tran_example2.gif)
Title: Re: Connecting Arduino to PIC
Post by: AWOL on Dec 26, 2012, 10:52 pm
Forget the circuits.
What does the PIC do when you connect the input to +5V or 0V?

(what do the PIC forums say?)
Title: Re: Connecting Arduino to PIC
Post by: oric_dan on Dec 27, 2012, 12:00 am
Quote
just tried it an hour ago, and it doesnt work.. tried both active low and active high..


You don't need a switch, just connect the pin to 0V or 5V. Since it's not working, as I
indicated a couple of days ago, "you might try using one of the Port B or C pins for the
input".

Title: Re: Connecting Arduino to PIC
Post by: retrolefty on Dec 27, 2012, 03:39 am
OK maybe a dumb question but I have to ask anyway. You do have a common ground wire connected between the arduino and the PIC, correct?

Lefty
Title: Re: Connecting Arduino to PIC
Post by: mauried on Dec 27, 2012, 05:15 am
What exactly is the PIC supposed to do.
You have set Port A and Port E to inputs.
Are you setting all the pins of Port A and Port E to some combination of logic levels.
The code seems to need a combination of logic to make something happen.
If you set pins to input, then you must connect either a 1 or a 0 to all the pins, or enable pullups ,otherwise they will float
and give erratic results.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 27, 2012, 08:04 am
Quote

Forget the circuits.
What does the PIC do when you connect the input to +5V or 0V?

(what do the PIC forums say?)


Quote

Quote
just tried it an hour ago, and it doesnt work.. tried both active low and active high..

You don't need a switch, just connect the pin to 0V or 5V. Since it's not working, as I
indicated a couple of days ago, "you might try using one of the Port B or C pins for the
input".


when i connect the pin to 5v it does what is it supposed to do..
it sends the output to the motor from portd..

Quote

OK maybe a dumb question but I have to ask anyway. You do have a common ground wire connected between the arduino and the PIC, correct?

Lefty

i powered the arduino from the vdd pin(ground) and vss pin(+5v) of the pic..
and i connected the arduino gnd to the digital gnd..

am i doing it wrong?..

Title: Re: Connecting Arduino to PIC
Post by: abrookfield on Dec 27, 2012, 02:41 pm
Quote

i powered the arduino from the vdd pin(ground) and vss pin(+5v) of the pic..
and i connected the arduino gnd to the digital gnd..

am i doing it wrong?..


vdd is normally +v, vss is normally 0v
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 27, 2012, 02:46 pm

Quote

i powered the arduino from the vdd pin(ground) and vss pin(+5v) of the pic..
and i connected the arduino gnd to the digital gnd..

am i doing it wrong?..


vdd is normally +v, vss is normally 0v


sorry i got it backwards, anyway is the wiring supposed to be like this:
(http://i47.tinypic.com/op6wlg.jpg)
im having doubts on using the pic pin as gnd so using the supply gnd will do right?..
Title: Re: Connecting Arduino to PIC
Post by: abrookfield on Dec 27, 2012, 02:58 pm
remove the link from "Input to pic" and "gnd"
Title: Re: Connecting Arduino to PIC
Post by: retrolefty on Dec 27, 2012, 02:58 pm


Quote

i powered the arduino from the vdd pin(ground) and vss pin(+5v) of the pic..
and i connected the arduino gnd to the digital gnd..

am i doing it wrong?..


vdd is normally +v, vss is normally 0v


sorry i got it backwards, anyway is the wiring supposed to be like this:
(http://i47.tinypic.com/op6wlg.jpg)
im having doubts on using the pic pin as gnd so using the supply gnd will do right?..


Well that drawing shows correct common grounding between the arduino and the PIC, but it also shows a permanent ground wired to the PIC input pin, which is certainly incorrect.

Lefty
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 27, 2012, 03:26 pm



Quote

i powered the arduino from the vdd pin(ground) and vss pin(+5v) of the pic..
and i connected the arduino gnd to the digital gnd..

am i doing it wrong?..


vdd is normally +v, vss is normally 0v


sorry i got it backwards, anyway is the wiring supposed to be like this:
(http://i47.tinypic.com/op6wlg.jpg)
im having doubts on using the pic pin as gnd so using the supply gnd will do right?..


Well that drawing shows correct common grounding between the arduino and the PIC, but it also shows a permanent ground wired to the PIC input pin, which is certainly incorrect.

Lefty


ok i finally got it to work using that wiring, but you said incorrect can i know where i should place the common ground?..
Title: Re: Connecting Arduino to PIC
Post by: retrolefty on Dec 27, 2012, 03:28 pm
Quote
ok i finally got it to work using that wiring, but you said incorrect can i know where i should place the common ground?..


Hard to understand what you are saying. Can you post a new drawing of how you have it presently wired and working?


Lefty
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 27, 2012, 03:44 pm
got it to work using this:
(http://i47.tinypic.com/op6wlg.jpg)

you said it was incorrect due to the pic input being permanently grounded, so where should i place the common ground?..
Title: Re: Connecting Arduino to PIC
Post by: AWOL on Dec 27, 2012, 03:47 pm
Quote
got it to work using this:

I don't think so.

See that node labelled "Input to PIC", and the one labelled "PIC PSU Gnd" and that solid black line that connects the two?
That's why it doesn't work.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 27, 2012, 03:49 pm

Quote
got it to work using this:

I don't think so.

See that node labelled "Input to PIC", and the one labelled "PIC PSU Gnd" and that solid black line that connects the two?
That's why it doesn't work.


i guess but im not sure if your saying i should do
"arduino output<resistor<pic input" and a different connection for the common ground?..
tried using vss for common ground but i dont know why it doesnt work..
Title: Re: Connecting Arduino to PIC
Post by: AWOL on Dec 27, 2012, 03:57 pm
That schematic is grounding your PIC input - that's a solid "LOW" on that input.
Connect the grounds together, but don't short an input to ground.
(unless it says "unused inputs should be tied to ground" somewhere in the datasheet. This is clearly not unused, because it is connected to an output from the Arduino.)
If you want a series resistor, I guess that's OK.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Dec 31, 2012, 01:22 pm
im really confused now, can you show me a schematic of the wiring on how i can connect the output from arduino to the input of the pic?..
it tried connecting it directly and it doesnt work.. can you please show me how.. do i need a transistor?..

will something like this work:
(http://i46.tinypic.com/51dopu.jpg) or (http://i50.tinypic.com/rri2cx.gif)
Title: Re: Connecting Arduino to PIC
Post by: oric_dan on Dec 31, 2012, 06:22 pm
I haven't been following this thread lately, but somehow the replies have gotten you
completely confused. In fact, your original ckts in posts #8 and #11 are ALL correct,
and since then, they are all wrong.

However, you possibly did not have a ground wire connected between the 2 processor
boards originally. So, forget everything else, and go back to your original ckts, and
where it says Gnd, just make sure that point goes to the grounds on both boards.
Title: Re: Connecting Arduino to PIC
Post by: siyete on Jan 09, 2013, 01:22 pm
need help again, i dont know if its my wiring or whathever but my arduino is rebooting/restarting..
im using this wiring:
http://i46.tinypic.com/51dopu.jpg

a 12v battery powers my pic16f877a and my arduino so that covers the common ground right?..

i cant pinpoint the reason why it is restarting..

1. power is not enough?..
2. my wiring is wrong so its rebooting?..
3. arduino low memory so its restarting?..
4. my arduino is damaged?..
5. any other reason you can think of...

need help.. thanks..
Title: Re: Connecting Arduino to PIC
Post by: fungus on Jan 09, 2013, 01:58 pm

OK maybe a dumb question but I have to ask anyway. You do have a common ground wire connected between the arduino and the PIC, correct?


Ya beat me to it...

Title: Re: Connecting Arduino to PIC
Post by: AWOL on Jan 09, 2013, 02:15 pm


OK maybe a dumb question but I have to ask anyway. You do have a common ground wire connected between the arduino and the PIC, correct?

Ya beat me to it...

Only two weeks later...
Title: Re: Connecting Arduino to PIC
Post by: siyete on Jan 09, 2013, 03:42 pm
does using the same power source not cover the common ground?..
they are parallel connected to the source..
Title: Re: Connecting Arduino to PIC
Post by: Docedison on Jan 11, 2013, 01:41 am
I think the point is that the pin marked "Input to Pic" should Not be grounded as it is also the output pin from the Arduino and would defeat the circuits proper operation.

Bob