PICAXE Data or Garbage?

Discussion in 'Embedded Systems and Microcontrollers' started by tracecom, May 20, 2010.

  1. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I have completed a project and am waiting for an LCD display for my PICAXE to arrive in the mail. My PICAXE-18X is sending the following via the Serial Out lead. If all is well, this serial data will be converted to parallel data and shown on the LCD display. My display didn't come in the mail today and I'm anxious to have some idea of whether or not my project is working. Does this look like gibberish, or does it look like data, or is there no way to tell?

    ÿ·ù÷õôÔ%òÿµõõóô—÷záÿµ÷û÷ôÚ÷öÍÿ·õõõô‹÷uÍÿ·ù÷õô´ñtÉÿ·ùõûô“÷záÿµ÷õ÷ô¶÷ráÿ·õõóô—÷vÁÿ·ù÷õø¶÷vÁÿµ÷û÷ô•ùtÉÿµ÷õ÷ô«÷vÍÿ·ùõûô“÷záÿµ÷õ÷ø´÷uÍÿ·ù÷õô”÷uÍÿµ÷õ÷ô·÷sáÿ»÷÷õô”õuÍÿµ÷ûõô«÷ôÍÿ»÷÷õô”õtÉÿµ÷ûõô•õtÉÿµõõ÷ø—÷vÁÿ·ù÷õô›÷záÿµõõ÷ô—÷vÁÿ³÷÷õô”÷uÍÿµ÷õ÷ð•ùvÁÿ»÷÷õô”õuÍÿµõõ÷ô—÷vÁÿ·õõ÷ø—÷vÁÿµõõóô—÷záÿ³÷÷õô”÷uÍÿµ÷õ÷ø—÷vÁÿµ÷ûõô”õuÍÿ«÷óõô•õtÉÿ·ù÷õô‹÷uÍÿ«÷óõô•õtÉÿ«÷÷õô”õuÍÿµ÷ûõô•ùtÉÿµ÷õ÷ô•õtÉÿµ÷õ÷ø—÷vÁÿµ÷õ÷ð•ùvÁÿ·ù÷õô”÷uÍÿµ÷õ÷ð•ùvÁÿµõõ÷ô—÷vÁÿµ÷õ÷ô•õtÉÿµ÷õ÷ø—÷vÁÿµ÷õ÷ø•ùvÁÿ·ù÷õô”÷uÍÿµ÷õ÷ð•ùvÁÿµ÷ûõô•ñtÉÿ«÷÷õô”÷uÍÿµ÷õ÷ø—÷vÁÿµ÷óõô”õuÉÿµ÷õ÷ô—÷váÿ«÷÷õô”÷uÍÿ»÷÷õô”õuÍÿµ÷ûõô•õtÉÿ·ù÷õô”÷uÍÿ³÷÷õô”÷uÍÿ·õõûô—÷rá
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
    Hello,

    It looks like the serial baudrate settings are wrong.
    When the baudrate is wrong the text will get garbled.
    Also the number of databits and parity will influence it.

    Bertus
     
  3. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    I concur. This appears to be a baudrate mismatch.
     
  4. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You are both correct. It's data. When I change the baud rate to 4800, here it is.

    1 71.67 50.3
    0 71.67 47.5
    1 71.67 50.3
    0 71.67 47.2
    1 71.67 50.3
    0 71.67 47.0
    1 71.67 50.3
    0 71.67 46.9
    1 71.67 50.3

    There are two data channels, but only one is connected to sensors (the 0 channel). The 71.67 represents the temperature in Fahrenheit and the 47.5 represents the relative humidity. It looks like the humidity sensor is working, but the temperature sensor is stuck for some reason.

    Thanks. :D
     
  5. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
    Hello,

    Are the temperature and humidity both analog signals?
    If so you can check the voltage for the tempareture and see if it changes.
    If the voltage changes but the display stays the same the code is not correct.

    Bertus
     
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Depending on the temp sensor, it may only update the temp a few times a second.

    If you read these all in a few milliseconds, it would not change.
     
  7. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    This is a published project from Peter Anderson. I don't pretend to understand the code but I built the circuit because I am interested in temperature and humidity measurement and I thought it would be a good introduction to PICAXE programming. Here is the code.

    Code ( (Unknown Language)):
    1.  
    2. ' HS1101_3.Bas
    3. '
    4. ' Illustrates an interface with two modules based on the Humirel HS1101 capacitive sensor
    5. ' configured with a 555 so as to generate a pulse train. Temperature is measured using a
    6. ' a NTC thermistor.
    7. '
    8. ' For each of the two Channel, 0 and 1, the external unit is powered by turning on the appropriate
    9. ' PinPower and, after a short delay to allow the 555 to settle, the Count is measured over the course
    10. ' one second. Ten times the RH (RH_10) is then calculated. Power is then removed from the external
    11. ' unit.
    12. '
    13. ' The temperature is then measured using an A/D converter and calculated using table lookup. This powerful
    14. ' technique in considered in a separate discussion.
    15. '
    16. ' The RH is then adjusted for temperature. I adjusted the RH up 0.1 percent for each degree above
    17. ' 25 degrees C and down 0.1 percent for each degree below 25 degrees C. I am not sure this is correct.
    18. '
    19. ' The Channel, Temperature and compensated RH are displayed for each channel.
    20. '
    21. ' PICAXE-18X RH Module 0
    22. '
    23. ' Out 2 (term 8) -- 1K ---------- Power for Channel 0
    24. ' In0 (term 17) <------------ Pulse train from 555
    25. '
    26. ' +5
    27. ' |
    28. ' 10K
    29. ' |
    30. ' ----- In6 (term 15)
    31. ' |
    32. ' |---------------------------- Thermistor ------- GRD
    33. '
    34. '
    35. ' GRD -------------------------- GRD
    36. '
    37. '
    38. ' PICAXE-18X RH Module 1
    39. '
    40. ' Out 3 (term 9) -- 1K ---------- Power for Channel 0
    41. ' In1 (term 18) <------------ Pulse train from 555
    42. '
    43. ' +5
    44. ' |
    45. ' 10K
    46. ' |
    47. ' ----- In7 (term 16)
    48. ' |
    49. ' |---------------------------- Thermistor ------- GRD
    50. '
    51. '
    52. ' GRD -------------------------- GRD
    53. '
    54. ' Things that I have not addressed.
    55. '
    56. ' How to deal with a clearly incorrect count measurement. How to deal with a relative
    57. ' calculation which is over 100. How to deal with an invalid temperature.
    58. '
    59. ' I did not test for temperatures below 0 degree C.
    60. '
    61. ' Uses about 300 bytes of program memory. Most of the EEPROM is used for the thermistor
    62. ' lookup table.
    63. '
    64. ' copyright, Peter H Anderson, Oct, '05
    65. Symbol Pulses = W0 ' used only in Sub MeasRH
    66. Symbol ADVal = W0 ' used only in Sub MeasTC
    67. Symbol RH_10 = W1 ' this is saved in Sub MeasTC for temporary use for ADValHi8 and ADValLow2
    68.  
    69. Symbol TC_100 = W2
    70. Symbol RHComp_10 = W3
    71. Symbol ADValHi8 = B8 ' used in Sub MeasTC
    72. Symbol ADValLow2 = B9 ' used in Sub MeasTC
    73. Symbol Diff = B10 ' used in Sub MeasTC
    74. Symbol N = B11 ' Used in Subs MeasTC and CompRH
    75. Symbol TC = B12 ' used in CompRH
    76. Symbol Whole = B8 ' used in Display Subs
    77. Symbol Fract = B9 ' used in Display Subs
    78. Symbol SignFlag = B10 ' used in DisplayTC
    79. Symbol Digit = B11 ' used in DisplayTC
    80. Symbol Channel = B13
    81. Symbol PinPower = B8 ' used only in MeasRH, Shared with Whole
    82. Symbol PinCount = B9 ' used in MeasRH, Shared with Fract
    83. Symbol PinTC = B9 ' used in MeasTC, Shared with Fract
    84.  
    85. Main:
    86. Channel = 0
    87. GoSub MeasRH ' result returned in RH_10
    88. ' need to deal with error
    89. GoSub MeasTC ' result returned in TC_100
    90. ' need to deal with error
    91. GoSub CompRH
    92. GoSub DisplayTC
    93. GoSub DisplayRH
    94. Channel = 1
    95. GoSub MeasRH ' result returned in RH_10
    96. ' need to deal with error
    97. GoSub MeasTC ' result returned in TC_100
    98. ' need to deal with error
    99. GoSub CompRH
    100. GoSub DisplayTC
    101. GoSub DisplayRH
    102. Pause 5000
    103. Goto Main
    104.  
    105. MeasRH:
    106. Lookup Channel, (2, 3), PinPower
    107. Lookup Channel, (6, 7), PinCount
    108. High PinPower ' turn on power to distant RH measurement circuitry
    109. Pause 1000 ' wait for unit to stabilize
    110. Count PinCount, 973, Pulses ' 973 is one second on the PICAXE-18X I tested
    111. Low PinPower ' remove power from distant RH measurement circuitry
    112. ' should test for obvious erroneous conditions
    113. ' RH_10 = 5577 - 0.759 * Num_Pulses
    114. RH_10 = 7 * Pulses / 10
    115. RH_10 = 6 * Pulses / 100 + RH_10
    116. RH_10 = 5 * Pulses / 1000 + RH_10
    117. RH_10 = 4 * Pulses / 1000 + RH_10
    118. RH_10 = 5577 - RH_10
    119. Return
    120. MeasTC:
    121. Lookup Channel, (0, 1), PinTC
    122. ReadADC10 PinTC, ADVal
    123. ADValHi8 = ADVal / 4 ' isolate the high 8 bits
    124. ADValLow2 = ADVal & $03 ' low two bits
    125. TC_100 = 10542 ' adjust this as required
    126. If ADValHi8 < 16 Then TooHot
    127. If ADValHi8 > 251 Then TooCold
    128.  
    129. For N = 0 to ADValHi8 ' continue to subtract
    130. Read N, Diff
    131. TC_100 = TC_100 - Diff
    132. Next
    133. ' Now for the low two bits, a linear interpolation
    134. N = N + 1
    135. Read N, Diff
    136. Diff = Diff / 4 * ADValLow2
    137. TC_100 = TC_100 - Diff
    138. MeasTCDone:
    139. Return
    140. TooHot:
    141. TooCold:
    142. TC_100 = $7fff
    143. GoTo MeasTCDone
    144. Return
    145. CompRH:
    146. ' Now adjust RH calculation for temperature
    147. RHComp_10 = RH_10 - 25 ' start at zero degrees C
    148. TC = TC_100 / 100
    149. SignFlag = TC / 128
    150. Branch SignFlag, (CompRHPostive, CompRHMinus)
    151. CompRHMinus:
    152. TC = TC ^ $ff + 1
    153. RHComp_10 = RHComp_10 - TC
    154. Goto CompRHDone
    155. CompRHPostive:
    156. RHComp_10 = RHComp_10 + TC
    157. Goto CompRHDone
    158. CompRHDone:
    159. Return
    160. DisplayTC:
    161. SignFlag = Tc_100 / 256 / 128
    162. If SignFlag = 0 Then TCPositive
    163. TC_100 = TC_100 ^ $ffff + 1 ' twos comp
    164. SerTxD ("-")
    165. TCPositive:
    166. SerTxD(#Channel, " ")
    167. Whole = TC_100 / 100
    168. Fract = TC_100 % 100
    169. SerTxD (#Whole, ".")
    170. ' be sure the fractional is two digits
    171. Digit = Fract / 10
    172. SerTxD (#Digit)
    173. Digit = Fract % 10
    174. SerTxD (#Digit)
    175. Return
    176. DisplayRH:
    177. Whole = RHComp_10 / 10
    178. Fract = RHComp_10 % 10
    179. SerTxD (" ", #Whole, ".", #Fract, 13, 10)
    180. Return
    181.  
    182. '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    183. ' EEPROM locations 0 - 15 not used
    184. EEPROM 16, (254, 236, 220, 206, 194, 183, 173, 164)
    185. EEPROM 24, (157, 149, 143, 137, 131, 126, 122, 117)
    186. EEPROM 32, (113, 110, 106, 103, 100, 97, 94, 92)
    187. EEPROM 40, (89, 87, 85, 83, 81, 79, 77, 76)
    188. EEPROM 48, (74, 73, 71, 70, 69, 67, 66, 65)
    189. EEPROM 56, (64, 63, 62, 61, 60, 59, 58, 57)
    190. EEPROM 64, (57, 56, 55, 54, 54, 53, 52, 52)
    191. EEPROM 72, (51, 51, 50, 49, 49, 48, 48, 47)
    192. EEPROM 80, (47, 46, 46, 46, 45, 45, 44, 44)
    193. EEPROM 88, (44, 43, 43, 43, 42, 42, 42, 41)
    194. EEPROM 96, (41, 41, 41, 40, 40, 40, 40, 39)
    195. EEPROM 104, (39, 39, 39, 39, 38, 38, 38, 38)
    196. EEPROM 112, (38, 38, 37, 37, 37, 37, 37, 37)
    197. EEPROM 120, (37, 36, 36, 36, 36, 36, 36, 36)
    198. EEPROM 128, (36, 36, 36, 36, 36, 35, 35, 35)
    199. EEPROM 136, (35, 35, 35, 35, 35, 35, 35, 35)
    200. EEPROM 144, (35, 35, 35, 35, 35, 35, 35, 35)
    201. EEPROM 152, (35, 35, 35, 35, 35, 35, 35, 35)
    202. EEPROM 160, (36, 36, 36, 36, 36, 36, 36, 36)
    203. EEPROM 168, (36, 36, 36, 37, 37, 37, 37, 37)
    204. EEPROM 176, (37, 37, 38, 38, 38, 38, 38, 39)
    205. EEPROM 184, (39, 39, 39, 39, 40, 40, 40, 41)
    206. EEPROM 192, (41, 41, 42, 42, 42, 43, 43, 43)
    207. EEPROM 200, (44, 44, 45, 45, 46, 46, 47, 47)
    208. EEPROM 208, (48, 48, 49, 50, 50, 51, 52, 53)
    209. EEPROM 216, (53, 54, 55, 56, 57, 58, 59, 61)
    210. EEPROM 224, (62, 63, 65, 66, 68, 70, 72, 74)
    211. EEPROM 232, (76, 78, 81, 84, 87, 90, 94, 98)
    212. EEPROM 240, (102, 107, 113, 119, 126, 135, 144, 156)
    213. EEPROM 248, (170, 187, 208, 235)
    214.  
     
    Last edited: May 20, 2010
  8. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Do a favor, edit your previous post and use the CODE tags.

    You can 'Go Advanced', Highlight your code, then click the '#' icon on the editor
     
  9. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
    Hello,

    For the temperature measurement the voltage of the voltage divider is measured.
    What kind of thermistor are you using?

    Bertus
     
  10. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    As I look at the code, it seems that the temperature is supposed to read out in Celsius, but it's clearly not 71.67 degrees C in the room where I am. I have troubleshooting to do. :)
     
  11. tracecom

    Thread Starter AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    It's a Vishay 10k NTC.
     
  12. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
Loading...