How to use serial commands for chip-chip communication?

tesladude

New Member
So I am used to using the rfin/rfout commands for wireless communication using ask transmitters. But they are too unreliable and weak for the project I am working on now. I am attempting to use serial transmitter modules but I cannot seem to figure out how to use the serin,serout. When I attempt to use these commands I am receiving data before I even send data and none of the variables I am receiving even match the ones I am sending So can somebody please explain how to use these commands properly and how they are supposed to act? I am just getting random numbers all over the place.
 
Last edited:

tesladude

New Member
RFIN & RFOUT work great. See my post at https://picaxeforum.co.uk/threads/easy-cheesy-433-mhz-radio-link.27904/

Complicating the issue is that you're never sure if the problem is on the transmitter or receiver end, and you're tweaking both codes simultaneously. Work slowly & methodically.

Also, half of the cheap eBay 433 Mhz modules are defective... that's why they are 99 cents for the pair. Stock up and test.

Thank you for the response. Sadly I need to use serin/serout for this project.
I took the modules out of the equation, I am sending b3 and b4 variables from one ic to the other by wire.
I send: b3(126) and b4(0)
yet I recieve b3(0) and b4(255).

here is my code:

Tx:
let b3=126
let b4=0
serout c.1,n9600_8,(b3,b4)
end


Rx:
high LED
serin rfpin,n9600_8,b3,b4
low led
end
 

erco

Senior Member
Haven't tried that, so all I can say is check the manual, there are examples in there.
 

inglewoodpete

Senior Member
The code above seems to be incomplete. How do you know that you are receiving 0 and 255? Timing is critical with serial communication. Deleting logging commands changes the timing and performance. Or are you using an oscilloscope to view the serial data received and the flashing LED?

I have found that the receiver modules that have an on-board crystal are much more reliable that the ones that don't. As far as I know, the transmitters all have a crystal.
 

Flenser

Senior Member
I am just getting random numbers all over the place
You can get garbage from serin if the baudmode constant specifies the wrong clock speed for either the tx or rx chip but this is just a guess. I can't tell if this might be the cause of you problems from the short code snippets that you have posted.

You will need to post your full code for the send and receive chips and tell us what chips you are using for each for the forum to be able to check things like this.

I took the modules out of the equation, I am sending b3 and b4 variables from one ic to the other by wire
Did you connect the serial between the two chips using two wires, ground and the serial line?
 

erco

Senior Member
Your process is correct to verify proper communicaton protocols using a direct wire connection (ground and signal wires) before attempting radio comms. It really is twice as hard syncing two Picaxes to talk, debugging two programs at once. Ideally you would have TWO computers displaying the serial monitor, one at each end, to really see what's going on. Or else, make one a remote repeater. Picaxe 1 sends a signal to Picaxe 2 (the repeater), which then send the signal back to PIcaxe 1. Obviously 3 lines are required here, two signal lines and ground. Always make sure that the transmitter's output connects to the receiver's input.

Both of your programs are one-shots. I suggest you loop continuously to get a steady data stream going. Also, it's important to start every program with a quarter or half-second pause to let the chip and power rails stabilize. And give the transmitter a longer pause than the receiver. That way the receiver is listening before the transmitter talks.
 
Last edited:

cachomachine

Senior Member
You can on the same computer have 2 programing editors running and debugging 2 picaxe chips using 2 different usb to ttl converters.
 

hippy

Technical Support
Staff member
I am attempting to use serial transmitter modules but I cannot seem to figure out how to use the serin,serout. When I attempt to use these commands I am receiving data before I even send data and none of the variables I am receiving even match the ones I am sending
If you are using 'dumb RF modules' with SEROUT and SERIN that can be quite tricky to get working.

You need to send preambles to wake the receiver up and synchronisation codes for the receiving PICAXE to be able to determine what is data and what is just noise. Something like this to transmit -
Code:
Do
  SerOut TX, T4800, ( "UUUUU" )
  Pause 5
  SerOut TX, T4800, ( "abc", b0 )
  b0 = b0 + 1
  Pause 1000
Loop
And something like this to receive -
Code:
Do
  SerIn RX, T4800, ( "abc" ), b0
  SerTxd( "Got ", #b0, CR, LF )
Loop
There has been quite extensive discussion on the forum regarding sending data with 'dumb RF modules' in the past and it would be worth reading up on that.

One thing, as suggested, is to get things working with a wired connection before adding the RF modules into the mix. If it doesn't work when wired it is unlikely to work when using RF.

A final point to note is that, if RFIN and RFOUT are not up to the task it may be that SEROUT and SERIN won't be either.
 

inglewoodpete

Senior Member
You can on the same computer have 2 programing editors running and debugging 2 picaxe chips using 2 different usb to ttl converters.
You can use one PE with two cables and two PICAXE windows open at the same time. Add the #COM xx directive to each program file to point them at their appropriate hardware.
 

mortifyu

New Member
Hello, you have certainly come to the right place for EXPERT help. The Guru's here are GOLD. Strike that... They're PLATINUM ;-)

Some time ago I was trying to achieve similar goals. I have now (thanks to the Guru's) been very successful with SERIN/SEROUT communications.

This, my initial thread asking for help and understanding that gave me a good appreciation...
https://picaxeforum.co.uk/threads/trouble-with-inter-picaxe-communications-serin-serout.28572/

I have found E-Byte modules such as these transceivers to be very worthy and work extremely well with PICAXE SERIN/SEROUT...
https://www.alibaba.com/product-detail/Ebyte-E32-TTL-100-100mW-SX1278_60624684495.html?spm=a2700.icbuShop.41413.8.4e8952050xyY6j

They do have many other modules available that may be more suitable for your needs. Best of all the prices are certainly bearable.


Earlier this year I wrote the below code to simply test the reliable range of a couple modules sending plenty of variables with different values. The tests were successful and gave me a clear indication of range.

MASTER:
Code:
'20X2
'E32-TTL-100 Transceiver
'Two Way Comms Testing 27-01-19
'MASTER

'~PINS~
'B.3 - LOCK - Transceiver OUTPUT - High=Sync complete, Low=incomplete
'B.4 - AUX - Transceiver
'B.5 - NOLINK LED
'B.6 - Receive - Transceiver's OUTPUT
'B.7 - LINK ACTIVE LED
'C.0 - Transmit - Transceiver's INPUT
'C.1 - RESET Button


''''''''''''''''''''''''''''''''''''
'MASTER
#define rb_code_master "rb6134997532"

'SLAVE
#define rb_code_slave "rb2997832165"
''''''''''''''''''''''''''''''''''''


init:
setfreq m32
setint %00000000,%00000010,C    'First set is state it changes to. 1=HIGH 0=LOW, second set selects which pin of port C. In this case Pin C.1
high c.0                'Set TX line HIGH for 'TRUE' data transmission

let b3=122
let b4=123
let b5=124
let b6=125
let b7=127
let b8=128
let b9=129
let b10=130
let b11=131
let b12=132
let b13=133
let b14=134
let b15=135
let b16=136
let b17=137
let b18=138
let b19=139
let b20=140
let b21=141
let b22=142
let b23=143
let b24=144
let b25=145
let b26=146
let b27=147
let b28=148
let b29=149
let b30=150
let b31=151
let b32=152
let b33=153

main:
random w0    'Generate a random number to transmit

waitreadytx:
if pinb.4=0 or pinb.3=0 then goto waitreadytx
pause 200
serout c.0,T9600_32,(rb_code_master,b0,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33)

waitreadyrx:
if pinb.4=0 or pinb.3=0 then goto waitreadyrx
pause 200
serin[3000, nolink],b.6,T9600_32,(rb_code_slave),b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33

if b2=b0 then inc w20 low b.5 high b.7 pause 50 low b.7 goto main endif

nolink:
sertxd("Link lost! ",#w20," Good links prior to link loss.  Sent: ",#b0,"  Received: ",#b2,cr,cr)
low b.7
high b.5
let b0=0
let b2=0
let w20=0
pause 600
goto main


interrupt:
reset

SLAVE:
Code:
'20X2
'E32-TTL-100 Transceiver
'Two Way Comms Testing 27-01-19
'SLAVE

'~PINS~
'B.3 - LOCK - Transceiver OUTPUT - High=Sync complete, Low=incomplete
'B.4 - AUX - Transceiver
'B.5 - NOLINK LED
'B.6 - Receive - Transceiver's OUTPUT
'B.7 - LINK ACTIVE LED
'C.0 - Transmit - Transceiver's INPUT


''''''''''''''''''''''''''''''''''''
'MASTER
#define rb_code_master "rb6134997532"

'SLAVE
#define rb_code_slave "rb2997832165"
''''''''''''''''''''''''''''''''''''


init:
setfreq m32
high c.0                'Set TX line HIGH for 'TRUE' data transmission

main:
if pinb.4=0 or pinb.3=0 then goto main
pause 200
serin[3000, nolink],b.6,T9600_32,(rb_code_master),b0,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33
sertxd("Received: ",#b0,cr)
low b.5
txwait:
if pinb.4=0 or pinb.3=0 then goto txwait
pause 200
serout c.0,T9600_32,(rb_code_slave,b0,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33)
high b.7
pause 50
low b.7
let b0=0
goto main


nolink:
low b.7
high b.5
let b0=0
let b3=0
let b4=0
let b5=0
let b6=0
let b7=0
let b8=0
let b9=0
let b10=0
let b11=0
let b12=0
let b13=0
let b14=0
let b15=0
let b16=0
let b17=0
let b18=0
let b19=0
let b20=0
let b21=0
let b22=0
let b23=0
let b24=0
let b25=0
let b26=0
let b27=0
let b28=0
let b29=0
let b30=0
let b31=0
let b32=0
let b33=0
goto main

Hope this helps.


Regards,
Mort.
 

mortifyu

New Member
Great info, Mort. You're officially a guru, too!
Thanks Erco, however I wouldn't go that far mate. I still come here asking stupidly simple things. :unsure::)

Best I can do from time to time to give back to this awesome community is offer my technical electronics skills.

Regards,
Mort.
 

Pongo

Senior Member
I have found E-Byte modules such as these transceivers to be very worthy and work extremely well with PICAXE SERIN/SEROUT...
https://www.alibaba.com/product-detail/Ebyte-E32-TTL-100-100mW-SX1278_60624684495.html?spm=a2700.icbuShop.41413.8.4e8952050xyY6j

They do have many other modules available that may be more suitable for your needs. Best of all the prices are certainly bearable.
I've been using E-Byte's 2.4 GHz modules, not the cheapest option but very solid performers in my experience.
 
Top