Good day
This is my second new post since I discovered picaxe a few months ago and I've learned so much. I did a very ambitious project (haven't played with pic's in a long time) building an incubator with a 20x2 and the SHT75 from sensirion displaying temp and humidity on a i2c LCD and it kept me up many a night. A lot of credit for my success must got to Charles Andrew(http://eprints.usq.edu.au/2406/) and the guy on phanderson.com. Also thanks for all the manuals rev ed. I started there as they uses 2 pins on the picaxe for data in and out. Then I got it working with just the clk and 1 wire saving me a pin that I can use somewhere else as the 20X2 has I/O pins. I would just like to share part of my code which might help someone along the line. Can I ask if someone can tell me more about the shift in routine. I get the picaxe to shifout the commands to the SHT but the reading it is a bit more complicated. I tried all the possible confiurations for reading MSB_in first and in 2 bytes as the SHT needs an acknowledge pulse before continuing. In the end I found a post by another smart person (sorry I do not know who you are as I was very focused on the code) who posted some shift_in_out routines and use it at the moment. Until I can figure a way out of getting shifting the data in.
[
'@@@@@@@@@@@@@@@@@@@@@@
' Interfacing SHT 75 with picaxe 20X2
'@@@@@@@@@@@@@@@@@@@@@@
' ==============I/O pins ================
Symbol CLK = c.2
Symbol SHTdata = c.1
Symbol Shtdatain = pinc.1
'====================Constants==========
Symbol MTemp = %00000011
Symbol MHum = %00000101
Symbol Statregwr = %00000110
Symbol Statregrd = %00000111
Symbol setup = %00000001
'====================Variables===========
Symbol Datalow = b0
Symbol Datahigh = b1
Symbol Datalow2 = b2
Symbol Datahigh2 = b3
Symbol Counter = b4
Symbol CMD = b5
Symbol dataword = W0
'====================Wait for VFD to initialize=================
setfreq m8
hsersetup B38400_8, %10 ' Setup baudrate for VFD comms
Pause 3000 ' give VFD time to start
'=====================Main Program=========================
Main:
Datalow = Mtemp 'Load temp measure command in datalow
gosub shtstart ' transmission start sequence
gosub writedata ' Write command to sensor
gosub acklow ' acknowlege send
pause 1000 ' Pause 500 ms to let sensor make reading
Dataword = 0 ' Make sure vairiable is 0
gosub readdata ' read sensor
gosub acklow ' acknowlege first byte received
Dataword = Dataword * 256 'Move byte to MSB byte as the sensor sends out MSB first
gosub readdata ' read sensor again
gosub ackhigh ' acknowlege send
Dataword = Dataword / 10 - 400 ' Do calculations for 14 bit
if Sot >= 40 then skipneg1 ' Check if value is negative
pause 20
dataword = 40 - Sot
Skipneg1:
datahigh2 = dataword / 100 +$30 ' convert to ASCII for display
datalow2 = dataword // 100
datahigh = datalow2 // 10 + $30
datalow2 = datalow2 / 10 + $30
hserout 0, ($0b, datahigh2, datalow2, ".", datahigh, $f8, "C") ' Send Data to VFD disp to display in degrees celcius
goto main
'===================================================
' TransStart ' 'Sensor Transmission Start Sequence, used to begin
'===================================================
ShtStart:
low clk 'START sequence
high shtdata
high clk
low shtdata
low clk
high clk
high shtdata
low clk
return
'=========================================
' WriteData ' 'Write Data byte in DataLow to Sensor '
'==========================================
WriteData:
shiftout clk, shtdata, 1, (Datalow/8) ' clock commands to the sensor
return
'=========================================
' AckHigh ''High Acknowledge to Sensor
'=========================================
Ackhigh:
high shtdata 'Output High
pulsout clk,10 'Pulse clock
return
'================================
' AckLow ' 'Low Acknowledge to Sensor '
'================================
Acklow:
low shtdata 'Output High
pulsout clk,10 ' 'Pulse clock
return
'========================================
' ReadData 'Read Byte from Sensor into DataLow
'========================================
ReadData:
input shtdata ' Shift in routine
for Counter = 1 to 8
datalow = datalow * 2
if shtdatain = 0 then skipMSBpre
Datalow = datalow + 1
skipMSBpre:
pulsout clk,1
next Counter
output shtdata
Return
]
Now that the project is nearly completed (just need to add the Stepper routine in) I feel very happy and would like to share and maybe save someone a lot of gray hairs.
This is my second new post since I discovered picaxe a few months ago and I've learned so much. I did a very ambitious project (haven't played with pic's in a long time) building an incubator with a 20x2 and the SHT75 from sensirion displaying temp and humidity on a i2c LCD and it kept me up many a night. A lot of credit for my success must got to Charles Andrew(http://eprints.usq.edu.au/2406/) and the guy on phanderson.com. Also thanks for all the manuals rev ed. I started there as they uses 2 pins on the picaxe for data in and out. Then I got it working with just the clk and 1 wire saving me a pin that I can use somewhere else as the 20X2 has I/O pins. I would just like to share part of my code which might help someone along the line. Can I ask if someone can tell me more about the shift in routine. I get the picaxe to shifout the commands to the SHT but the reading it is a bit more complicated. I tried all the possible confiurations for reading MSB_in first and in 2 bytes as the SHT needs an acknowledge pulse before continuing. In the end I found a post by another smart person (sorry I do not know who you are as I was very focused on the code) who posted some shift_in_out routines and use it at the moment. Until I can figure a way out of getting shifting the data in.
[
'@@@@@@@@@@@@@@@@@@@@@@
' Interfacing SHT 75 with picaxe 20X2
'@@@@@@@@@@@@@@@@@@@@@@
' ==============I/O pins ================
Symbol CLK = c.2
Symbol SHTdata = c.1
Symbol Shtdatain = pinc.1
'====================Constants==========
Symbol MTemp = %00000011
Symbol MHum = %00000101
Symbol Statregwr = %00000110
Symbol Statregrd = %00000111
Symbol setup = %00000001
'====================Variables===========
Symbol Datalow = b0
Symbol Datahigh = b1
Symbol Datalow2 = b2
Symbol Datahigh2 = b3
Symbol Counter = b4
Symbol CMD = b5
Symbol dataword = W0
'====================Wait for VFD to initialize=================
setfreq m8
hsersetup B38400_8, %10 ' Setup baudrate for VFD comms
Pause 3000 ' give VFD time to start
'=====================Main Program=========================
Main:
Datalow = Mtemp 'Load temp measure command in datalow
gosub shtstart ' transmission start sequence
gosub writedata ' Write command to sensor
gosub acklow ' acknowlege send
pause 1000 ' Pause 500 ms to let sensor make reading
Dataword = 0 ' Make sure vairiable is 0
gosub readdata ' read sensor
gosub acklow ' acknowlege first byte received
Dataword = Dataword * 256 'Move byte to MSB byte as the sensor sends out MSB first
gosub readdata ' read sensor again
gosub ackhigh ' acknowlege send
Dataword = Dataword / 10 - 400 ' Do calculations for 14 bit
if Sot >= 40 then skipneg1 ' Check if value is negative
pause 20
dataword = 40 - Sot
Skipneg1:
datahigh2 = dataword / 100 +$30 ' convert to ASCII for display
datalow2 = dataword // 100
datahigh = datalow2 // 10 + $30
datalow2 = datalow2 / 10 + $30
hserout 0, ($0b, datahigh2, datalow2, ".", datahigh, $f8, "C") ' Send Data to VFD disp to display in degrees celcius
goto main
'===================================================
' TransStart ' 'Sensor Transmission Start Sequence, used to begin
'===================================================
ShtStart:
low clk 'START sequence
high shtdata
high clk
low shtdata
low clk
high clk
high shtdata
low clk
return
'=========================================
' WriteData ' 'Write Data byte in DataLow to Sensor '
'==========================================
WriteData:
shiftout clk, shtdata, 1, (Datalow/8) ' clock commands to the sensor
return
'=========================================
' AckHigh ''High Acknowledge to Sensor
'=========================================
Ackhigh:
high shtdata 'Output High
pulsout clk,10 'Pulse clock
return
'================================
' AckLow ' 'Low Acknowledge to Sensor '
'================================
Acklow:
low shtdata 'Output High
pulsout clk,10 ' 'Pulse clock
return
'========================================
' ReadData 'Read Byte from Sensor into DataLow
'========================================
ReadData:
input shtdata ' Shift in routine
for Counter = 1 to 8
datalow = datalow * 2
if shtdatain = 0 then skipMSBpre
Datalow = datalow + 1
skipMSBpre:
pulsout clk,1
next Counter
output shtdata
Return
]
Now that the project is nearly completed (just need to add the Stepper routine in) I feel very happy and would like to share and maybe save someone a lot of gray hairs.