Retransmit Serial to Bluetooth

julianE

Senior Member
I have a setup where I'm sending 2 bytes of data over 433 MHz modules, in this case soil moisture measurements.
I also send battery voltage and internal chip temperature. I have an 08M2 send the received data to the PC using SERTXD and it works perfect but I wanted to add another wrinkle and have another 08M2 receive the data and immediately retransmit it through bluetooth instead of sertxd.

Sertxd works flawless but the bluetooth loses data. I'm thinking it's a timing issue, the 433 MHz module transmits 2 bytes of data and waits 1 second between transmission, I guess I can bring in the transmitters and modify them for a longer pause between transmissions but they are battery powered and I wanted to keep the sleep time as long as possible. Right now I have the transmitter 08M2 run at 4 Mhz for the reading/data transmission portion and then lower the speed to 250 Khz for the sleep portion, I transmit every 5 minutes or so and the battery usage is minimal.

I have tried HSEROUT and it's a little better but not perfect.

There must be something special with the SERTXD relative to other serial transmission. I guess I can always put an inverter on the sertxd output and drive the bluetooth module that way.

I'm sure I can think of a workaround but I thought I'd ask, thanks in advance for any help.

Code:
setfreq M8
high C.4	'set up serial port for T setting, needs to be high
pause 10

Main:
Serin C.2, N1200_8,("ABC"),b0,b1      'Receive from 433 Mhz module, data is always sent 2 bytes at a time with at least 1 second pause
'Sertxd (#b0,",",#b1, cr, lf)              

Serout C.4,T9600_8,(#b0,",",#b1, cr, lf)   'Send to Bluetooth module
Goto main
 

hippy

Technical Support
Staff member
Start with simpler code, just send something via Bluetooth and check that is reliably received by the PC ..

Code:
setfreq M8
high C.4	'set up serial port for T setting, needs to be high
pause 10

Main:
b0 = b0 + 1
b1 = b0 + 1
Serout C.4,T9600_8,(#b0,",",#b1, cr, lf)   'Send to Bluetooth module
Pause 2000
Goto main
 

julianE

Senior Member
Thanks for the quick reply. I tried your suggestion and my phone terminal is receiving flawless bluetooth data.
 

rossko57

Senior Member
That begs the question about why the posted example does not work so well, all that is different is looping to the SERIN between sends.

I note that using the # format in the serout means the Picaxe has to some do formatting work between sending bytes, the bluetooth module may not behave nicely about varying intercharacter gaps in the serial stream. Bear in mind it will be making up data packets from incoming serial stream, and will look for pauses to do its thang.
You might play with pre-formatting a message, to be squirted out in a single hit (hserout should be better at that) or it might just all go away at 16Mhz.
 

hippy

Technical Support
Staff member
That begs the question about why the posted example does not work so well, all that is different is looping to the SERIN between sends.
My thoughts are the same. It might now be worth ceating a hard-wired transmitter ( rather than wireless ), feeding that to the bridge between serial and Bluetooth ...

Transmitter:
Code:
setfreq M8
Main:
b0 = b0 + 1
b1 = b0 + 1
Serout C.1, N1200_8, ( "ABC", b0, b1 ) ' <-- Choose an appropriate pin
Pause 2000
Goto main
Bridge:
Code:
setfreq M8
high C.4	'set up serial port for T setting, needs to be high
pause 10

Main:
Serin C.2, N1200_8,("ABC"),b0,b1
Serout C.4,T9600_8,(#b0,",",#b1, cr, lf)   'Send to Bluetooth module
Goto main
One thing I note is that you say "I transmit every 5 minutes or so and the battery usage is minimal". So perhaps it is related to the Bluetooth module going to sleep or something similar ?

Assuming the above works, replace the 'PAUSE 2000' in the transmitter so it transmits less frequently, working up to once every five minutes to see if that still works.
 

julianE

Senior Member
Thanks for all the replies. I did change the pause value between transmissions on the transmitter side from 1 second pause to 2 and it helped. There might be something to the 5 minutes between transmissions because I made another transmitter that was sending continues stream of data with 2 second pauses between transmissions and it worked perfect.

I'm running into another issue, that of range on cheapo 433 Mhz modules, I think the maximum distance that's reliable is around 10 meters.

Rossko's idea of sending everything at once is very valid, would make for a cleaner program too. I have to think that through. My scheme for data sending is very simple, b0 variable has an "address" type value for example 32 and the variable b1 is the data, sensor reading. If it's a word variable I just send the other byte of data with an address one higher
i.e. 33. My plan is to have a program on a PC receive data and save it keyed to the "address" information. I don't have any method to deal with transmitters sending data simultaneously I'm relying on different sending times, plan is to have different sleeping times on different boxes transmitting, besides, if there is data loss and I miss some data it's not crucial to have the data every 5 minutes it can come every 30 minutes and still be of use. Sending everything in one quick stream would help a lot with collision issues.

The bluetooth retransmission is just so I can see the data flowing on a portable device. I was also considering having a two way interaction with a picaxe using bluetooth, I've done it before on other projects and it works well. As of now, I'm considering having the retransmission box store the data on a 24lc256 EEPROM and spew it out once it receives a request from bluetooth.

I'll have to scrounge for some free time to test all this. Thanks again for all the help, I stand in a shadow of giants.
 

julianE

Senior Member
I have some more information. To follow Hippy's dictum I simplified further. Just the Bluetooth bridge and a transmitter module. If I am near the 433 MHz receiver, 2 to 3 meters, data flows perfect but if i move the transmitter further afield I start getting dropped information, the sequence of numbers skips by 5 counts. My RF knowledge is sketchy been out of school for a long time now. Could it be that the Bluetooth transmissions are overwhelming the 433 Mhz receiving stage, the bluetooth module is on the same breadboard as the 433Mhz receiver module. The receiving module connected to a PC without bluetooth has been working well, rarely a dropped byte. I have to read up more on bluetooth but my initial guess, once the pairing occurs there is a constant conversation between two devices, if it were not so I would just turn the module off and on as needed but once bluetooth is paired it has to stay on. On all my other projects I basically use the Bluetooth as a display device this is the first time I'm trying to have two RF devices on a same board. I think it would be useful to get this bridge working because bluetooth and a phone are very convenient display devices. I'll research using a better device something like RFM22.
 

hippy

Technical Support
Staff member
You could try placing a baking tray or a sheet of metal connected to 0V between the 443MHz receiver and Bluetooth module, taking care not short anything out. Or simply SERTXD out from the bridge, try with and without Bluetooth attached, see if there is a correlated difference.

You could also try increasing the preamble sent by the transmitter to see if that helps lock the bridge onto the receiver better. Perhaps post the relevant parts of the transmitter code in case there's anything in that which deserves comment.
 

srnet

Senior Member
I'll research using a better device something like RFM22.
Once the software is set up right, FSK devices like the RFM22B are very reliable. The data packets are CRC checked, so corrupt data is extremely rare, close to non-existent really.

The RFM22B is capable of long range also, the current record for a PICAXE & RFM22B telemetry link (@ 100mW) is circa 1200km, the best I have managed is meagre 1000km, complete failure I am.
 

julianE

Senior Member
the best I have managed is meagre 1000km, complete failure I am.
Don't beat yourself up srnet, you'll do better in time :) Congrats on the insanely successful Picaxe in space project, just brilliant.
I'll be happy to get a decent 15 meter range.

Hippy, the issue is the Bluetooth module. I ran a test with SERTXD out from the bridge and as soon as I unplug the bluetooth module all is perfect, plug it back in and the data is wonky. I have not tried isolating the bluetooth from the 433 receiver. I don't think having metal between them will help much since the antenna of the 433 MHz receiver has to be exposed and same with bluetooth. I might try separating the two modules by 1/2 a meter or so. The other possibility is having 2 batteries in the transmitter box, a 5 volt for the picaxe and a 9 volt for the 433 Mhz transmitter thereby increasing the RF transmitting power.

I'll also order the RFM22B and pour through srnet's tutorials to learn how to use it.

Thanks for all the help.
 
Top