Shift_in_out 20X2 and SHT 75

dorfusf

New Member
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:confused:. 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:confused:. 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.
 

Andrew Cowan

Senior Member
Looks like a nice project! You can tidy up your post by using the [code]...[/code] things around your code, and more people will view it if you report in the finished projects section. Well done on the first project!

Andrew
 
Last edited:

dorfusf

New Member
Thank you very much for your replies. I tried the quote thingies but I see now what I did wrong. Also sorry for putting it in the sandbox thingie I'm new to forums as I never really found one that I actually want to belong to. As soon as my project is finnished I'll put it in the completed project part for ohter people to use. I think I'm going to leave the Shift_in part as Westaust55 said the pin might not be swithching fast enough and the project is working. I just want to complete it too so I can start the next project.
 

westaust55

Moderator
[ Moved to active Forum ]
but somehow my response was left in the sandbox. Added here for completeness

A few thoughts for you:

But note that while I have used SHIFTOUT, I have not used SHIFTIN

1. the SHT75 sends back two bytes of data so you will need to use SHIFTIN with a word variable or two bytes

shiftin sclk, sdata,mode, (w0\16)
or
shiftin sclk, sdata,mode, (b1\8, b0\8)

2. The SHT75 expects an open collector with a pull up resistor.

You will need to look at doing this with the sdata pin for your X2 chip.

An alternative to start might be to put a resistor in series with the PICAXE pin used as the output and then connect the SHT75 data pin also to a separate pin as an input. I suggest this as an initial test as the PICAXE just might not be able to change the direction of a pin fast enough.

Think that the mode will need to be MSBPost_L - that is, clock then sample data and the data idles low (due to open collector configuration sought by SHT75)

note also: you have posted into the sand box which is really a test area.
The best place to post any questions is the Active Forum area at:
http://www.picaxeforum.co.uk/forumdisplay.php?f=2
__________________
 

dorfusf

New Member
Good day all

I've finished my project. Andrew Cowan mentioned that I should put my project in the completed projects. There is only one problem as it limmits you to 10000 charachters and my code with comments is over 25000. So if someone wants the code for and SHT75 measuring temperature and humidity and controlling an incubator just send me a message and I'll email it to you.
 

westaust55

Moderator
Good day all

I've finished my project. Andrew Cowan mentioned that I should put my project in the completed projects. There is only one problem as it limmits you to 10000 charachters and my code with comments is over 25000.
You could save the BASIC “.bas’ file with say a “.dsn” file extension and upload as an attachment to your post.
Then provide some words and photos for your finished project.
 
Last edited:
Top