Pages: [1] 2 3   Go Down
Author Topic: Connecting Arduino to PIC  (Read 3367 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?..
« Last Edit: December 24, 2012, 01:15:04 am by siyete » Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is the pic expecting input where your hooking up to? its a software driven device like the arduino
Logged


Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes i configured all PORTA to input, here is part of my code for the pic:

Code:
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..
« Last Edit: December 24, 2012, 03:20:01 am by siyete » Logged

Australia
Offline Offline
Sr. Member
****
Karma: 11
Posts: 467
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the 16f887 have some kind of program in it ?
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes the pic16f877a is programmed to receive input
and the arduino is programmed to produce output..
both use digital signal..
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 158
Posts: 2882
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Australia
Offline Offline
Sr. Member
****
Karma: 11
Posts: 467
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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: but ill try using a 2n3904 transistor:


Logged

0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 158
Posts: 2882
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


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..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25735
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

(what do the PIC forums say?)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 158
Posts: 2882
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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".

Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2 3   Go Up
Jump to: