Buzby
Senior Member
Hi,
This post came about when I re-thought my 'Option 4' in this thread : http://www.picaxeforum.co.uk/showthread.php?27676-Addressing-scheme-for-RS485-stubs-or-quot-slaves-quot&p=285838&viewfull=1#post285838
The idea back then was to write an app that could flash the screen on a phone to set the node number of a slave, and send the physical co-ordinates to the Master via Bluetooth. This would need a Bluetooth module and a lot of phone programming.
It would be much better if an app already existed. Well, it does !
There are now plenty apps in the app stores that can send Morse Code via the camera flash.
The phone apps ( I used TESLA LED from the Android app store ) let you type in text, which it then sends as flashes of light.
A photodiode is connected to the PICAXE, and then PICAXE decodes the pulses of light into ASCII characters, for use as you want.
This demo just uses the letters RGB to operate 3 LEDs, but it could be used to send a room name and sensor number to a slave node.
The photodiode I used was not very sensitive, that's why the phone is lying directly on it. A better photodetector and maybe a lens would give much better performance.
One thing to watch with ( at least with TESLA LED ) is that sometimes the app get the timings wrong, so bad you can see and hear it. It only seem to happen when the app has been sending continuously for about 30 mins, probably due to some memory garbage collection or something.
I don't know if this is of any use to anybody, but I enjoyed proving it can be done !.
Cheers,
Buzby
https://www.youtube.com/watch?v=X-UddZxMWNw&feature=youtu.be
This post came about when I re-thought my 'Option 4' in this thread : http://www.picaxeforum.co.uk/showthread.php?27676-Addressing-scheme-for-RS485-stubs-or-quot-slaves-quot&p=285838&viewfull=1#post285838
The idea back then was to write an app that could flash the screen on a phone to set the node number of a slave, and send the physical co-ordinates to the Master via Bluetooth. This would need a Bluetooth module and a lot of phone programming.
It would be much better if an app already existed. Well, it does !
There are now plenty apps in the app stores that can send Morse Code via the camera flash.
The phone apps ( I used TESLA LED from the Android app store ) let you type in text, which it then sends as flashes of light.
A photodiode is connected to the PICAXE, and then PICAXE decodes the pulses of light into ASCII characters, for use as you want.
This demo just uses the letters RGB to operate 3 LEDs, but it could be used to send a room name and sensor number to a slave node.
The photodiode I used was not very sensitive, that's why the phone is lying directly on it. A better photodetector and maybe a lens would give much better performance.
One thing to watch with ( at least with TESLA LED ) is that sometimes the app get the timings wrong, so bad you can see and hear it. It only seem to happen when the app has been sending continuously for about 30 mins, probably due to some memory garbage collection or something.
I don't know if this is of any use to anybody, but I enjoyed proving it can be done !.
Cheers,
Buzby
Code:
' Decode morse generated by 'TESLA LED' app from Android playstore
' Uses Magic Morse algorithm (c) 2011 by Mickey R. Burnette
#picaxe 28X2
#no_table
#no_data
' ================================================================================
' Magic Morse tables stored in EEPROM
' ================================================================================
' All mappings are 5-bit with exception of ", . ? @" which are 6-bit
' mappings squeezed into the 5-bit space by dropping the 6th bit
EEPROM 0, (0,"E","I","S","H","5",0,0,0)
'EMPTY 6, 7, 8
EEPROM 9, ("T","N","D","B","6",0,0,0,0)
'EMPTY 14, 15, 16, 17
EEPROM 18,("A","R","L",0,0,0,0,0)
'EMPTY 21, 22, 23, 24, 25
EEPROM 26,("M","G","Z","7",0,0,0,0,0)
'EMPTY 30, 31, 32, 33, 34
EEPROM 35,("U","F",0,0,0,0)
'EMPTY 37, 38, 39, 40
EEPROM 41,("i",0) 'i == INVITE
'EMPTY 42
EEPROM 43,("K","C",0,0,0,0,0,0)
'EMPTY 45, 46 ,47, 48, 49, 50
EEPROM 51,("W","P",0,0,0,0,0,0)
'EMPTY 53, 54, 55, 56, 57, 58
EEPROM 59,("O",0)
'EMPTY 60
EEPROM 61,("8",0,0,0,0,0,0)
'EMPTY 62, 63, 64, 65, 66, 67
EEPROM 68,("V","u",0,0,0,0,0,0) 'u == UNDERSTOOD
'EMPTY 70, 71, 72, 73, 74, 75
EEPROM 76,("X","/",0,0,0,0,0,0,0,0,".",0,0,0,0,0) 'SLASH=77 PERIOD=86
'EMPTY 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91
EEPROM 92,("Q",0,0,0,0,0,0,0,0)
EEPROM 101,(0,"?",0,0,0,0,0) 'QUESTION MARK=102
'EMPTY 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107
EEPROM 108,("Y",0,0,0,0,0,0,0)
'EMPTY 109, 110, 111, 112, 113, 114, 115
EEPROM 116,("J",0,0,0,0,0,0,0,0)
'EMPTY 117, 118, 119, 120, 121, 122, 123, 124
EEPROM 125, ("9",0,0,0,0,0,0,0)
'EMPTY 126, 127, 128, 129, 130, 131, 132
EEPROM 133, ("4") : EEPROM 134, ("(") : EEPROM 135, ("c") : EEPROM 136, (")")
EEPROM 137, (" ") : EEPROM 138, ("M") : EEPROM 139, (".") : EEPROM 140, ("R")
EEPROM 141, (".") : EEPROM 142, ("B") : EEPROM 143, ("U") : EEPROM 144, ("R")
EEPROM 145, ("N") : EEPROM 146, ("E") : EEPROM 147, ("T") : EEPROM 148, ("T")
EEPROM 149, ("E")
EEPROM 156, (32) ' S_07 = SPACER CHARACTER
EEPROM 158, (",") ' COMMA MAPPING
EEPROM 159, (100) ' DIT timing variable
EEPROM 160, (0) ' AVAILABLE
EEPROM 161, (0) ' AVAILABLE
'
EEPROM 162, (">",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' > == STARTING
'EMPTY 163 - 181
EEPROM 182, ("@",0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' @ ==182
'EMPTY 183 - 196
EEPROM 197, ("3")
' Following Block of EEPROM available for customizations / future options-enhancements
EEPROM 198, (0) : EEPROM 199, (0) : EEPROM 200, (0) : EEPROM 201, (0)
EEPROM 202, (0) : EEPROM 203, (0) : EEPROM 204, (0) : EEPROM 205, (0)
EEPROM 206, (0) : EEPROM 207, (0) : EEPROM 208, (0) : EEPROM 209, (0)
EEPROM 210, (0) : EEPROM 211, (0) : EEPROM 212, (0) : EEPROM 213, (0)
EEPROM 214, (0) : EEPROM 215, (0) : EEPROM 216, (0) : EEPROM 217, (0)
EEPROM 218, (0) : EEPROM 219, (0) : EEPROM 220, (0) : EEPROM 221, (0)
EEPROM 222, (0) : EEPROM 223, (0) : EEPROM 224, (0) : EEPROM 225, (0)
EEPROM 226, (0) : EEPROM 227, (0) : EEPROM 228, (0)
'EMPTY 198 - 228 ' 31
EEPROM 229, ("2",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
'EMPTY 230 - 244 ' 15
EEPROM 245, ("1",0,0,0,0,0,0,0)
'EMPTY 246 - 252 ' 7
EEPROM 253, ("0",0,0)
'EMPTY 254, 255 ' 2
' ================================================================================
' || End of Magic Morse tables ||
' ================================================================================
' ================================================================================
' || Symbols ||
' ================================================================================
SYMBOL DitDah = b1 ' Used in MM algorithm
SYMBOL Point = B2 ' Used in MM algorithm
SYMBOL RXedChar = B3 ' ASCII value after decoding morse
SYMBOL PulseNow = b4 ' Current state of input
SYMBOL PulseMem = b5 ' Memory for 1-shot
SYMBOL EoWflag = b6 ' Set when end of word detected
SYMBOL time_0 = w4 ' Duration of idle time, ie. gap between Dits and Dahs
SYMBOL time_1 = w5 ' Duration of active time, ie. Dit or Dah
SYMBOL DITtimv = w6 ' Max length of a Dit
SYMBOL EoLtimv = w7 ' End of Letter timer value
SYMBOL EoWtimv = w8 ' End of Word timer value
SYMBOL PhotoIn = pinC.2 'The signal from the photodetector
SYMBOL actvLED = C.4 ' Activity LED, flashes in time with input
SYMBOL BLUled = pinA.0 '
SYMBOL GRNled = pinA.1 ' Demo LEDs
SYMBOL REDled = pinA.2 '
' ================================================================================
' || Code starts here ||
' ==============================================================================
setfreq m16 ' Run at 16MHz
settimer 65500 ' Preset timer reload to make timer tick faster
low A.0 '
low A.1 ' Demo LEDs
low A.2 '
' Set morse speed parameters
DITtimv = 450 ' Max length of a Dit
EoLtimv = 700 ' End of Letter time
EoWtimv = 1000 ' End of Word time
do ' Main loop
PulseNow = PhotoIn ' Get current state of input pin
if PulseNow <> PulseMem then ' If state changed since last scan,
if PulseNow = 0 then ' 0 = Active, Dit or Dah
high actvLED ' Turn on activity LED
time_0 = timer ' Record length of last idle
timer = 0 ' Reset timer
if time_0 > EoLtimv then ' End of letter time
DitDah = DitDah + Point ' Complete the two-part pointer
READ DitDah, RxedChar ' Read mapped character from EEPROM
sertxd(RxedChar," ")
if time_0 > EoWtimv then ' End of word
EoWflag = 1
sertxd(cr,lf)
else
EoWflag = 0
endif
point = 0 ' Reset point count
DitDah = 0 ' Reset address workbyte
gosub ProcessChar ' Call routine to process RXedChar
endif
else ' 1 = Inactive, line idle
low actvLED ' Turn off activity LED
time_1 = timer ' Record length of last flash
timer = 0 ' Reset timer
inc point ' increment point on any Dit or Dah
if time_1 < DITtimv then ' Dit, do nothing
sertxd(".")
else ' Dah, update address
sertxd("-")
Select Case Point
Case 1 : DitDah = DitDah OR %00001000
Case 2 : DitDah = DitDah OR %00010000
Case 3 : DitDah = DitDah OR %00100000
Case 4 : DitDah = DitDah OR %01000000
Case 5 : DitDah = DitDah OR %10000000
End Select
endif
endif
PulseMem = PulseNow ' Update memory
endif ' End of state changed logic
loop ' End of main loop
' ================================================================================
' || Subroutines ||
' ================================================================================
ProcessChar:
' Put code here to handle the received data as each character is decoded.
' The EoWflag is set if the character is also the end of a word.
if RXedChar = "B" then
inc BLUled ' Toggle blue led
endif
if RXedChar = "R" then
inc REDled ' Toggle red led
endif
if RXedChar = "G" then
inc GRNled ' Toggle green led
endif
return
https://www.youtube.com/watch?v=X-UddZxMWNw&feature=youtu.be