View previous topic :: View next topic |
Author |
Message |
McuMike
Joined: 13 Feb 2016 Posts: 3
|
Posted: Fri Feb 19, 2016 5:05 pm Post subject: RS232 Help needed.. **** Solved **** |
|
|
Hi, I want to send data from my greenhouse using Bluetooth modules HC-05.
On a receiver in my house with a nokia 5110 display i want to see: Temperature, Air moisture, Soil moisture, batt-voltage, etc.etc.
There is no need for the receiver to display data all the time, it can stay in idle and just wake up for incoming data when the transmitter wants to connect and auto-pair, lets say.. once every 10 minutes to preserve battery. (receiver is solar-charged). Display wakes up on button.
I asked about a way to make sure the values ends up where they belong, and not 12.5 volts in Temperature variable due to some glitch in transmission.
Lots of wireless projects i seen is either "send and hope for the best". Or 300 lines of code with RTS/CTS, Timing, CRC checking, and god knows what..
Now i solved this issue with some small and easy code..
(BASCOM-AVR version : 2.0.7.8 )
Last edited by McuMike on Sun Feb 21, 2016 5:14 am; edited 2 times in total |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Fri Feb 19, 2016 6:44 pm Post subject: |
|
|
take a look at AN #113 - Green House controller
there is some good info about Uart sorting Rx/Tx data _________________ / Kim |
|
Back to top |
|
|
McuMike
Joined: 13 Feb 2016 Posts: 3
|
Posted: Fri Feb 19, 2016 6:51 pm Post subject: Help with RS232 ********* SOLVED ********* |
|
|
Thanks. Even if AN#113 uses very simple fm trans/rec. It sends data without the receiver really knowing what data is going where. Temperature might as well end up as Moisture variable with disturbance in signal. (Grandm'a pushing her 422 MHz "fell out of wheelchair panic transmitter") in the middle of a greenhouse transmission.
To be 100% sure that sent variables ends up in their right container, requires more code & using CTS/RTS.
Surely AN#113 code works fine, but i want to rule out disturbances in transmission, (even if it in this case is just a greenhouse monitor). No offense
So, instead of sending one by one with timing issues, i send 1 string in an NMEA-like-format. With 9600bps it's done in 20mS.
This is without error checking, but that is easily done. And a token could be sent in the tx-string to tell the receiver what the string is all about.
Just like in an NMEA string.
The code is a bit dirty, but small & explain-friendly.
And ofcourse it works..
Code: | '-------------------------------------------------------------------------------
' COMMASEPARATED SERIAL BLUETOOTH TEST
' *** RECEIVER ***
'
'
' The transmitter sends a combined string of variables, comma separated.
' Just like NMEA: 22.5,80.4,55,12.72 and CR
' | | | |
' | | | |- Battery
' | | |- moist in soil
' | |- moist
' |- temp
'
'Error checking can (if needed) easily be done with checksum as last in the string.
'When received, the string is splitted into an array, then separated into 4 strings
'and converted to Value. (more useful than a string)
'
'-------------------------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 1000000 'No good for 9600 Baud.. can optimize later.
$baud = 9600
$hwstack = 40
$swstack = 40
$framesize = 40
$lib "glcd-Nokia3310.lib"
Config Single = Scientific , Digits = 1 'Cuts down to 1 decimal, enough for me
Config Portd = Output
Config Graphlcd = 128x64sed , Rst = Portb.0 , Cs1 = Portb.1 , A0 = Portb.2 , Si = Portb.3 , Sclk = Portb.4
Config Serialin0 = Buffered , Size = 50
Dim Akey As Byte
Dim S As String * 50
Dim Ar(5) As String * 5
Dim Bcount As Byte
Dim Tempstr As String * 5 , Moiststr As String * 5 , Soilstr As String * 5 , Voltstr As String * 5
Dim Temp As Single , Moist As Single , Soil As Single , Volt As Single
Enable Interrupts
Initlcd
Cls
Setfont Font6x8
Do
Akey = Inkey() ' Get a char from buffer
If Akey = 13 Then Goto Process ' Is transmission ended with CR?
S = S + Chr(akey) ' Not finished? Ok. fill up S some more.
Loop
'===============================================================================
Process:
Bcount = Split(s , Ar(1) , ",")
Tempstr = Ar(1) : Temp = Val(tempstr)
Moiststr = Ar(2) : Moist = Val(moiststr)
Soilstr = Ar(3) : Soil = Val(soilstr)
Voltstr = Ar(4) : Volt = Val(voltstr)
Cls
Lcdat 1 , 10 , "Volt : " ; Volt
Lcdat 2 , 10 , "Moist: " ; Moist
Lcdat 3 , 10 , "Soil : " ; Soil
Lcdat 4 , 10 , "Temp : " ; Temp
End
$include "font6x8.font"
|
I have tried some different approaches on using wireless serial, and it won't get much easier than this..
A bit overkill with all single-variables and not optimized string sizes, but it's only for testing..
And code gets a bit big mainly beacuse of the display chosen.
Update
HC-05 has no sleepmode.. Useless in battery powered projects. When connected 3-4mA, but when searching 25mA !! No,No.
I'll use the HM-10 BLE module instead. Same footprint, longer range, sleepmode, a mode for direct remote control of I/O's, and only 3$
http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2047675.m570.l1313.TR0.TRC0.H0.Xhm-10+ble.TRS0&_nkw=hm-10+ble&_sacat=0 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|