Pages: [1]   Go Down
Author Topic: Picaxe/Arduino Serial Communication  (Read 865 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Essentially I am attempting to serially communicate between a Picaxe 14M and an Arduino UNO, with the aim being that I can utilise the Picaxe as a slave to undertake low-level activities that require a large number of pins (I'll eventually swap it out with maybe a 40 pin Picaxe).

However, while sending date from the Arduino to the Picaxe, I am failing to receive the correct bytes into my Picaxe variables, although sending a string (in this case "initialise") seems to work fine when used as a qualifier. I'm not sure whether transmitted data is T or N, but both give me junk values. T always returns '105' regardless of the serial value sent, and N returns '75'.

In addition, the Arduino doesn't seem to be receiving any data from the Picaxe, despite the connection between the being fine. Below is some the code I am trying just to get it all working:

Picaxe:
Code:
serin 4, T2400, ("initialise"), b1
debug
serout 1, T2400, (42)
serin 4, T2400, b2
debug
serout 1, T2400, (54)
serin 4, T2400, b3
serin 4, T2400, b4
debug
end

Arduino:
Code:
void setup(){
  Serial.begin(2400);
}

void loop(){
  int out1 = 1;
  int out2 = 2;
  int num1;
  int num2;
  Serial.write("initialise");
  Serial.write(out1);
  while(Serial.available() == 0){}
  num1 = Serial.read();
  Serial.write(out2);
  while(Serial.available() == 0){}
  num2 = Serial.read();
  Serial.write(num1);
  Serial.write(num2);
}

Any help would be great - thanks.
« Last Edit: December 06, 2013, 09:38:07 am by MerrickKing » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you using both N2400 and T2400, surely it's one or the other.

Also this seems to be pretty dependant on which processor fires up first.

And what does

serin 4, N2400, ("initialise"), b1

do? Because you never send that string from the Arudino.

Rather than trying to get this working both ways right from the get go I would verify the comms in each direction first by just sending and reading bytes from P to A, then vice versa.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 56
Posts: 1849
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Program this into your PICAXE and then work with the Arduino to receive the transmission reliably:

http://www.picaxeforum.co.uk/entry.php?93-QBF-(Quick-Brown-Fox)-Serial-Test-Generator


Ray
Logged

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

@Graynomad, this was sloppy copying and pasting on my part - I was halfway through mixing code around when I posted this. The N in the Picaxe program should have been a T. The line
Code:
serin 4, T2400, ("initialise"), b1
reads the incoming data into the variable b1, but first must receive the qualifier "initialise". Again, sloppy copying as I omitted
Code:
Serial.write("initialise");
from the Arduino code accidently.

~Hope this helps
« Last Edit: December 06, 2013, 09:40:15 am by MerrickKing » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8621
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, then I refer to my last paragraph, don't try to get everything working at once.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

So I've wittled the code down to the bare basics, and am still receiving '105' all the time. Also, my Picaxe program doesn't seem to run the loop I want it to...

Code:
symbol Counter = b0

do{
serin 4, T2400, Counter
debug
}loop
Logged

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 56
Posts: 1849
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe PICAXE BASIC questions would be best directed to:
http://www.picaxeforum.co.uk/forumdisplay.php?2-Active-PICAXE-Forum
I'm sure you'll get a quick reply from our friends over there...

However
Quote
with the aim being that I can utilise the Picaxe as a slave to undertake low-level activities that require a large number of pins (I'll eventually swap it out with maybe a 40 pin Picaxe

The ATmega1284p-PU is a DIP 40-pin 8-bit uC that can simply replace the need to have a PICAXE, IMO.  I guess if you already have the code for the PICAXE then maybe using to separate uC makes a weebit of sense, but you seem to be having a significant amount of issues which is another way to say maybe moving to something less complex would be a consideration?
If you are interested in the 1284, CrossRoads (and likely others) have a nice, inexpensive board available.  The uC is under $5 and I think I paid under $4 but I buy in quantity > 25.  I have 3 of CrossRoads boards and they are beautiful.  The other nice thing about the 1284 is that you'll be running at 16-MHz which means 16 MIPS of compute power and with 16K of SRAM.  Here an older reference thread to browse:
http://forum.arduino.cc/index.php?PHPSESSID=3mkdavppenep01s96e94m3ebn4&topic=80483.225

Edit:
If you do not need all that SRAM and do not want to build a board, just buy a Mega2560.  I've used bunches of these in projects and they are a real workhorse .

To give you an idea of what I think about the PICAXE compared to the Arduino, I just gave away $150 worth of PICAXE chips and USB programmers to an acquaintance  - now a friend smiley    You can do some serious stuff with a PICAXE but IMO the effort to make PICAXE BASIC perform is simply NOT worth my effort.  If you need to use a PIC for some reason, then go with a real BASIC compiler:  OshamSoft comes to mind because I own it but there are plenty of other good compilers, some free.  Revolution Education (PICAXE) simply is not geared-up to support the diversity of product as found in the Arduino: their market is UK and Old Empire educational markets - hobbyists generate very little, if any, sustained revenue. 


Ray
« Last Edit: December 10, 2013, 11:31:04 am by mrburnette » Logged

Pages: [1]   Go Up
Jump to: