Inconsistant serial input problem

tonto2k

Member
Hi, I am having some trouble interfacing a bluesmirf bluetooth module and a picaxe 28x1. I can send serial commands over a terminal(lynxterm) on my laptop via bluetooth, but sometimes the commands don't display correctly.

I am using a picaxe 28x1 with 4 LED outputs(pins 1,2,3,4) and one serial input (pin8). The bluesmirf is configured at 4800bps therefore I haven't needed to change the picaxe frequency.

In operation I type either 1,2,3 or 4 and the corresponding LED lights up on the picaxe. My problem is sometimes I press a number and the led doesn't light up.

I am quite new to serial communications and I have been looking on the forum and googled quite a bit but I am still struggling !

Hope somebody can point me in the right direction please :)

Thanks.
 

Attachments

hippy

Technical Support
Staff member
[ Moved to Actice Forum ]

Code:
serin 8,N4800,b1
if b1 = 231 then goto greenflash
if b1 = 51 then goto yellowflash
if b1 = 230 then goto redflash
if b1 = 25 then goto greenflash2
Pin 8 ;-)

What's more intriguing are the values the charcters you are matching with; these aren't standard ASCII codes for numbers "1" through "4". I suspect there's some baud rate or polarity issue.
 

tonto2k

Member
Is pin 8 the wrong input pin for serin? I am using an axestack 28 board and pin 8 is the first input on it. I have read a little about hserin would these pins be better for serial comms?

The numbers are a little strange ! I got them by debugging b1 and basically wrote down each value for each number 1 - 4.

My terminal settings are: port: com10, baud:4800 data bits 8, stop bits 1, parity 1, flow control none.

The Bluesmirf configuration settings are:
baud: 4800 Parity: none Mode: slave authen=0 encrp=0 pincod = 1234 bonded=0 rem=none set

Thanks for the help :)
 

hippy

Technical Support
Staff member
I'm not familiar with the axestack boards but 28X1 pins are numbered 0 through 7.

I'm also not familiar with Bluesmirf but suspect it uses TTL-UART protocol. You could try the following and see if you get more sensible/ readable information received when you send a character -

#Picaxe 28X1
#Terminal 4800
Do
SerIn 0, T4800, b1
SerTxd( "Received = ", b0, CR, LF )
Loop
 

ciseco

Senior Member
Just to rule this out as I fell foul of something fishy a while back. The 28x1's I had, the internal frequency was out a bit. I was having to use the calibfreq command, to the tune of -5 or -6 to get reliable comms at just 9600. Worth a try will only take a few minutes to try going up and down and see if things get better/worse. Might be nothing to do with this, just thought as it's so simple to test it was worth a mention.

Miles
 

tonto2k

Member
I entered the code you suggested and it works :)

Only problem I have now is I have to wait a few seconds before I press another number otherwise the picaxe thinks I am sending a 2 char value. Do you know what command I could use so the picaxe recieves only 1 character at a time?

Here is the receiving code:

main:
SerIn 8, T4800, b1
if b1 = "1" then goto greenflash
if b1 = "2" then goto yellowflash
if b1 = "3" then goto redflash
if b1 = "4" then goto greenflash2
SerTxd( "Received = ", b1, CR, LF )
goto main

Thanks.

I'm not familiar with the axestack boards but 28X1 pins are numbered 0 through 7.

I'm also not familiar with Bluesmirf but suspect it uses TTL-UART protocol. You could try the following and see if you get more sensible/ readable information received when you send a character -

#Picaxe 28X1
#Terminal 4800
Do
SerIn 0, T4800, b1
SerTxd( "Received = ", b0, CR, LF )
Loop
 

hippy

Technical Support
Staff member
Only problem I have now is I have to wait a few seconds before I press another number otherwise the picaxe thinks I am sending a 2 char value.
Not really sure how you mean; perhaps you could provide more details.
 

eclectic

Moderator
tonto
Perhaps modify your code to

Code:
main:
SerIn 8, T4800, b1 
SerTxd( "Received = ", b1, CR, LF )

if b1 = "1" then goto greenflash
if b1 = "2" then goto yellowflash
if b1 = "3" then goto redflash
if b1 = "4" then goto greenflash2
goto main
e
 

tonto2k

Member
Hi thanks for the replies.

Hippy: If i press any of the numbers fast enough (more than once every 2 or 3 seconds) the leds do not light and the code on the sertxd reads a letter instead of a number?

For instance if I press 1 quickly, I get "q", if i press 2 quickly I get "r". If I press 3 quickly I get "s", If I press 4 quickly I get "t". I was thinking maybe the terminal was sending "11" or "111" and the picaxe was interpretting it like that?

Eclectic: I originally had my code as you suggested and it made no difference unfortunately, I have modified it like you said just in case though !
 

hippy

Technical Support
Staff member
It could be that you are pressing keys while the PICAXE is in the LED flashing routine, by the time the PICAXE again executes SERIN the byte sent and being output by the Bluesmirf module is already going by and only the tail-end data of that is received. This would exhibit itself as corrupt data.

Try this and see if it responds better -

main:
SerIn 8, T4800, b1
SerTxd( "Rx=", b1, CR, LF )
Goto main

If it does it probably is timing related. It may be possible to resolve that by moving to background serial receive with HSERSETUP / HSERIN.
 

tonto2k

Member
Hi just tried the code you suggested Hippy and it made no difference to the output. I still get q,r,s, or t if i press more than once a second.

Do you think if I increased the speed to 9600bps it might update a bit faster?

I am going to look into hserin like you say too :)
 

eclectic

Moderator
Hi just tried the code you suggested Hippy and it made no difference to the output. I still get q,r,s, or t if i press more than once a second.

Do you think if I increased the speed to 9600bps it might update a bit faster?

I am going to look into hserin like you say too :)
Just some ramblings out loud.

a. Please post a reference/Datasheet for an "Axestack"

b. 1 2 3 4 = ASC 49 50 51 52

c. q r s t = ASC 113 114 115 116

e
 

hippy

Technical Support
Staff member
It's difficult to really say what's going on; unknown terminal emulator, via unknown bluetooth transmitter, to unknown bluetooth receiver to PICAXE on unknown hardware - "unknown" to me anyway.

I know SERIN will capture data correctly and not corrupt it as long as the data arriving is correct, isn't sent before it's ready to receive and there's a baud rate match. The real question is whether what the PICAXE is receiving is correct or not - Do you have an oscilloscope ?
 

tonto2k

Member
Solved !! Hserin to the rescue :)

I researched hserin and found a bluetooth-picaxe thread on the forum :)

http://www.picaxeforum.co.uk/showthread.php?t=16029&highlight=hserin&page=5

Post 45 on page 5, Copied the code and changed it to:

hsersetup B4800_4,%00 'setup hserin port pin15 for 4800 baud

main:

hserin 0,1
ptr=0
get 0,b1

debug b1

Select b1

Case = 97 '"a" key
High 1
Pause 10
Low 1

Case = 98 '"b" key
High 2
Pause 10
Low 2

Case = 99 '"c" key
High 3
Pause 10
Low 3

Case = 100 '"d" key
High 4
Pause 10
Low 4

Else Goto main

Endselect

Goto main

Now I can just change the ascii keys to whatever I choose :)
It works and it works great !!!

@eclectic: I got the Axestack28 board from the US about two years ago, Its quite useful it puts all the pins on one side (which is good for breadboarding)

Heres the link: http://www.hvwtech.com/products_view.asp?ProductID=521
The PDF is in the "download resources" section on the page.

Thanks for the help guys
 
Top