Shop OBEX P1 Docs P2 Docs Learn Events
Can anyone Help With Atlas PH stamp on propeller — Parallax Forums

Can anyone Help With Atlas PH stamp on propeller

Igor_RastIgor_Rast Posts: 357
edited 2012-10-08 11:43 in Propeller 1
Ive just recieved my ph stamp of atlas that I was waiting for for so long,


Ive tryed everything but I cant seem to get the simple code to work

if got my stamp connecter tx stamp - pin8 propeller , rx stamp - p7 propeller

And to get started I need to send a simple asci code to the stamp and wait for the reply..

hope anyone can help me with some code to send then recive the data from the stampp

here a link of the datasheet of the stamp , so you can see the simple commands
https://www.atlas-scientific.com/index.php/datasheets?task=document.viewdoc&id=1


hope to get some help soon
Igor
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-02-01 12:33
    This is not a Parallax Basic Stamp. It's another company's product that has nothing to do with Parallax. Unfortunately, we can't help you with this Stamp.

    The Propeller should be able to work though. You might download the Simple_Serial I/O driver from the Propeller Object Exchange. This can do ordinary serial I/O up to 9600 Baud. Alternatively, you could download the BS2_Functions object from the Propeller Object Exchange. This provides many of the functional pieces that are implemented as statements in Parallax's Stamp Basic, but as Spin subroutines and functions. There's some explanation in the source code comments for each of the objects. If you're using the Propeller Tool for Propeller programming, these object may already be included in the installation folder.
  • TappermanTapperman Posts: 319
    edited 2012-02-01 12:41
    Have you checked out this video already?

    http://www.youtube.com/watch?v=UIk6CAINpwo

    ... Tim
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 12:54
    I modified my SayIt bridge program to act as a bridge to your pH Stamp.

    Set your teminal window to 57600 baud and let me know if this program works.
    CON
      _Clkmode = xtal1 + pll16x     ' 80MHz  
      _Xinfreq = 5_000_000          
      ' Pin Assignments
     
      _pHTx = 7                  ' Connected to Rx on pH Stamp
      _pHRx = 8                  ' Connected to Tx on pH Stamp
      _DebugTxPin = 30
      _DebugRxPin = 31
     
      _PhBaud = 38400
      _DebugBaud = 57600
       
    OBJ
      Com[2] : "FullDuplexSerial"                 ' uses two cog
      
    PUB Main | localIndex, localAttmpts
      
      Com[0].start(_DebugRxPin, _DebugTxPin, 0, _DebugBaud)
      Com[1].start(_pHRx, _pHTx, 0, _pHBaud)
      waitcnt(clkfreq / 4 + cnt)
      repeat
        result := Com[0].rxcheck
        if result <> -1 and result <> 0
          Com[1].tx(result)
        result := Com[1].rxcheck
        if result <> -1 and result <> 0
          TbugTx(result)
    PRI TbugTx(localCharacter)
      if (localCharacter > 31 and localCharacter < 127) or localCharacter == 13
        
        Com[0].tx(localCharacter) 
           
      else
        
        Com[0].tx(60)
        Com[0].tx(36)
        Com[0].hex(localCharacter, 2)
        Com[0].tx(62)
       
        
      
    

    Try typing "L1" followed by enter (and without the quotes) into the terminal window. The LED on the pH Stamp should light up.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 13:04
    Igor,

    I do a lot of pH testing. I'm very curious what you think of your pH Stamp.

    I hope you let us know how it works.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 14:10
    ok , I understand what yo mean , but I must be able to control it using the proppeller and a LCD connected to it

    so this far I am
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    VAR
    byte command
    
    byte ph
    obj
    PST :"Parallax Serial Terminal"
      debug : "SerialMirror"  
        BS2 : "BS2_Functions"    ' Create BS2 Object
        gg: "simple_serial"
    PUB Main
     Debug.start(31, 30, 0, 115200) 
     gg.init(8, 7,38400)
    
     waitcnt(cnt+ clkfreq/2) 
    
      BS2.Serout_Char(7,"E",38400,BS2#NInv,8)
       BS2.Serout_Char(7,13,38400,BS2#NInv,8)
       Debug.Str(String("Telling Stamp Listen",13))
    
    repeat
    
       
       waitcnt(cnt+ clkfreq*2)
    
       BS2.Serout_Char(7,"R",38400,BS2#NInv,8)
       BS2.Serout_Char(7,13,38400,BS2#NInv,8)
       Debug.Str(String("Asking PH",13))  
       
       waitcnt(cnt+ clkfreq/2)
       BS2.SERIN_STR (8,ph,38400,1,8)
    

    The light on the stamps blinks like it get's the command to execute a single reading

    but when I try to get the reading , the program stalls at the Serin routine

    can you help me whit the problem
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 14:19
    He Duane , Your program works good as a heck . Im busy all day this is the first I see, all the commands looks to be working fine

    So thank you alot

    on the other hand , Im fairly new to the propeller and I struggle my way around with most code's but I don't understand a thing of how it works,
    how can I get the data to be displayed in a lcd
    or mean can you help me with it

    im trying for some time allready to make a PH & Ec controller . to Get it wright I decided to get theres stamps.
    some help would be great
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 14:22
    A couple of problems jump out.
    BS2.SERIN_STR (8,ph,38400,1,8)
    

    you need an address symbol "@" in front of "ph".
    BS2.SERIN_STR (8,[COLOR=#ff0000]@[/COLOR]ph,38400,1,8)
    

    ph also needs enough bytes to hold all the characters that are returned.
    VAR
    
      byte ph[16]
    

    Use the above, if don't ever expect to receive more than 15 characters.

    You'll also want a way of displaying the received data.
    Debug.Str(@ph)
    
    

    The above should display the received data.

    It would probably be a good idea to zero out the byte array between reading from the pH Stamp. If the number of characters received isn't always the same, you could end up having old charaters in your array.

    The following code will fill the array with zeros.
    bytefill(@ph, 0, 16)
    

    Edit: Igor, I hadn't seen your last post when I wrote this. Let me know if you're still having trouble.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 14:28
    IMG00242-20120201-2325.jpg


    This is how the controller looks like now :P
    1024 x 1365 - 152K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 14:40
    Igor,

    Mike's comment about Simple Serial's baud rate limited reminded me BS_Functions has the same limit.
    Mike Green wrote: »
    This can do ordinary serial I/O up to 9600 Baud.

    You'll probably want to use Parallax Serial Terminal or FullDuplexSerial.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 14:42
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    VAR
    byte command
    
     
    byte ph[16]
    obj
    PST :"Parallax Serial Terminal"
      debug : "SerialMirror"  
        BS2 : "BS2_Functions"    ' Create BS2 Object
    
    PUB Main
     Debug.start(31, 30, 0, 115200) 
     waitcnt(cnt+ clkfreq/2) 
    
    
     Debug.Str(String("step 1",13))
      BS2.Serout_Char(7,"E",38400,BS2#NInv,8)
       BS2.Serout_Char(7,13,38400,BS2#NInv,8)
       Debug.Str(String("step 2",13))
       Debug.Str(String("Telling Stamp Listen",13))
    
    repeat
    
       
       waitcnt(cnt+ clkfreq*2)
    
       Debug.Str(String("step 3",13))
       
       BS2.Serout_Char(7,"R",38400,BS2#NInv,8)
       BS2.Serout_Char(7,13,38400,BS2#NInv,8)
       Debug.Str(String("Asking PH",13))
       
       Debug.Str(String("step 4",13))
       
       waitcnt(cnt+ clkfreq/2)
    
       Debug.Str(String("Step 5",13))
       
       BS2.SERIN_STR (8,@ph,38400,0,8)
       
       Debug.Str(String("step 6",13))
       
    
       
       Debug.Str(@ph)  
      Debug.Str(String("step 7",13))  
    

    it still get's stuk at the step 5 so at the recive ?????
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 14:47
    Yes but I never understud thos commands , ok sending is one part , that I got

    but recieving the data was always a problem for me , espesialy withe the timming etc.

    you have any idear how a simple code looks like for the fullduplexserial

    it needs to

    send
    step 1 send - E,13

    step 2 send - R,13

    step 3 recive the data

    display the data

    later ill adjust to let the stamp temperture compensate , I have a DS18b20 temp sensor also connected to the stamp to take care of that part for me

    igor
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 15:31
    Igor,

    I think this should get you started.
    CON
      _Clkmode = xtal1 + pll16x     ' 80MHz  
      _Xinfreq = 5_000_000          
      ' Pin Assignments
     
      _pHTx = 7                  ' Connected to Rx on pH Stamp
      _pHRx = 8                  ' Connected to Tx on pH Stamp
      _DebugTxPin = 30
      _DebugRxPin = 31
     
      _PhBaud = 38400
      _DebugBaud = 57600
      _BufferSize = 50
       
    VAR
      byte messageBuffer[_BufferSize]
      
    OBJ
      Com[2] : "Parallax Serial Terminal"                 ' uses two cog
      
    PUB Main | localIndex, localAttmpts
      Com[0].StartRxTx(_DebugRxPin, _DebugTxPin, 0, _DebugBaud)
      Com[1].StartRxTx(_pHRx, _pHTx, 0, _pHBaud)
      waitcnt(clkfreq / 4 + cnt)
      Com[1].str(@endCmd)
      
      repeat
        Com[1].str(@readCmd)
        Com[1].StrIn(@messageBuffer)
        Com[0].char(13)
        Com[0].str(@messageBuffer)
        bytefill(@messageBuffer, 0, _BufferSize)
        waitcnt(clkfreq * 2 + cnt)
    DAT
    endCmd        byte "E", 13, 0
    readCmd       byte "R", 13, 0
    continuousCmd byte "C", 13, 0
     
    

    The program only sends the "end" command once. From the documentation, it looked like it only needed to be sent once.

    I haven't tested this code and I don't use the "StrIn" method very often (if ever) but I think this code should work.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-01 16:10
    Thanks man < it works fine now, this way I can adjust it later to work in the program the way I know how to work with it

    thanky you verryyy veryyy much , Ill keep you posted on how the status of the project is , scool also killing all my time ,

    and im waiting on a ec probe so I can setup the ec stamp *** well

    o almost forgot

    I was going to use temperture dependant readings so . I have a ds1820 sensor connected also and this put's the temp on the lcd,

    how can I make the code accept the temp variable to send in place of the R to get a temperture compensated reading

    the temp code looks like this now in this stage , but works so far
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      OW_DATA           = 14                                 ' 1-wire data pin
    
      SKIP_ROM          = $CC                               ' 1-wire commands
      READ_SCRATCHPAD   = $BE
      CONVERT_T         = $44
    
      CLS               = $00                               ' clear screen
      HOME              = $01                               ' home
      CR                = $0D                               ' carriage return
      DEG               = $B0                               ' degree symbol
       #8, BKSP, TAB, LF
    
       RS = 0                         {lcd control}
      RW = 1                         {lcd control}
      E  = 2                         {lcd control}
      DBLow  = 3                      {lcd control}
      DBHigh = 6                      {lcd control}
    
    
      PSTClearScreen = 16
    OBJ
       LCD : "LCD_20x4" 
      term : "jm_txserial"
      'term          : "tv_text"
      ow            : "OneWire"
      fp            : "FloatString"
      f             : "FloatMath"                           ' could also use Float32
    
    VAR
    
    long tempc  ,temp1,temp
      
    PUB main 
      
    LCD.Init( E, RS, RW, DBHigh, DBLow )                            {LCD init}
    LCD.usDelay( 5_000 )                                            {LCD init}
    LCD.Clear
    
    term.init(30, 115_200)                                        ' start VGA terminal
    
    
      ow.start(OW_DATA)                                     ' start 1-wire object, pin 0
    
      ' read temperature and update display every second
      repeat
        tempC := getTemperature                             ' get temperature in celsius
                 
        
        
         LCD.RawSetPos( $02 )
                             
        LCD.PrintStr(fp.FloatToFormat(temp1, 5, 1))
        LCD.PrintStr( string(" C" ))
    
        
        waitcnt(cnt+clkfreq)
      
    PUB getTemperature 
      ow.reset                                              ' send convert temperature command
      ow.writeByte(SKIP_ROM)
      ow.writeByte(CONVERT_T)
    
      repeat                                                ' wait for conversion
        waitcnt(cnt+clkfreq/1000*25)
        if ow.readBits(1)
          quit
    
      ow.reset                                              ' read DS1822 scratchpad
      ow.writeByte(SKIP_ROM)
      ow.writeByte(READ_SCRATCHPAD)
      temp := ow.readByte + ow.readByte << 8                ' read temperature
      temp1 := F.FDiv(F.FFloat(temp), 16.0)                  ' convert to floating point
    

    Ill hear from you later , gonna cath a sleep now , tomorrow early scool again

    thanks again
    & hope to hear more from you , help like you is priceless
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-01 16:58
    It shouldn't be hard to send the temperature information to the pH Stamp. You'll just use the "dec" method in PST.

    If you're not just sending integer values, you'll have to use some other steps.

    You'll also want to calibrate the meter with buffer solutions. If your meter isn't calibrated, the temperature correction isn't going to matter since you'll likely have greater errors from not calibrating the meter than you'll have from temperature differences.

    It's too bad the pH Stamp doesn't output the millivolt readings because then you could add extra calibration options into your program.

    I've found my pH meter had a hard time accurately measuring pHs around 2 when just calibrated with buffer of 7.00 and 4.00. I have to use a 1.68 buffer and 4.00 buffer to calibrate the meter when I want to measure low pH levels.

    It's best if you can "frame" the pH you wish to measure with buffers above and below the value to be measured.

    I hope you know about using an appropriate soaking solution for your electrode. Don't soak it in distilled water. pH electrodes will go bad over time (kind of like a battery).

    When you get your EC Stamp, you'll need to use a resistor of at least 3.3K between it and the Prop to protect the Prop from the 5V signal levels.

    When I read some data sheets on the type of ADC used in pH meters they stressed the importance of keeping the electronics clean. They strongly suggested using finger cots when handling the chip.

    pH electrodes don't provide a signal that is easy to read for just any ADC chip.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-02 06:56
    IMG00244-20120202-1608.jpg
    Ok Duane, Ive tyred all day again , hihih

    before I get to sending te temperture to the PH stamp to get a temperture compensated reading , I began to figure a way to calculate with the numbers

    I want to get the difference between the mesured Ph of the stamp and a Target_PH value that I set( just a constant now, later ill add it in a lcd menu)

    now the problem looks like I can't get the Ph value that is stored in message buffer to become a floating point valve , so I can make a simple subtraction



    target PH - actual Ph = diference

    this diference is later used to let the pumps know howmuch to dose

    Can you help me with the string to float ???

    hope to hear soon
    igor
    CON
    
       _clkmode = xtal1 + pll16x
       _xinfreq = 5_000_000
    
      buton1 =9                    {input buttons }
      buton2 =10                    {input buttons }
      buton3 =11                    {input buttons }
      buton4 =12                     {input buttons }
      
      RS = 0                         {lcd control}
      RW = 1                         {lcd control}
      E  = 2                         {lcd control}
      DBLow  = 3                      {lcd control}
      DBHigh = 6                      {lcd control}
    
      CR  = 13
      LF  = 10
      PSTClearScreen = 16
    
      tempsensor = 14
      vlotter = 13
    
      
      _pHTx = 7                  ' Connected to Rx on pH Stamp
      _pHRx = 8                  ' Connected to Tx on pH Stamp
      _DebugTxPin = 30
      _DebugRxPin = 31
     
      _PhBaud = 38400
      _DebugBaud = 57600
      _BufferSize = 50
    
      Target_PH     = 7.1
                                       
    
      SKIP_ROM          = $CC                               ' 1-wire commands
      READ_SCRATCHPAD   = $BE
      CONVERT_T         = $44
    
      CLS               = $00                               ' clear screen
      HOME              = $01                               ' home
                                   ' carriage return
      DEG               = $B0                               ' degree symbol
       #8, BKSP, TAB
    VAR
    
      byte messageBuffer[_BufferSize]
     long tempc  ,temp1,temp   ,diference,delta    ,ph     ,ph1
     
    OBJ
    
      Com : "Parallax Serial Terminal"                 ' uses two cog
      ow            : "OneWire"
       fp            : "FloatString"
      f             : "FloatMath"   
     
      LCD : "LCD_20x4"
    
      
    PUB Main | localIndex, localAttmpts
    
      ow.start(tempsensor)
      
      LCD.Init( E, RS, RW, DBHigh, DBLow )                            {LCD init}
      LCD.usDelay( 5_000 )                                            {LCD init}
      LCD.Clear
    
    
      
      Com.StartRxTx(_pHRx, _pHTx, 0, _pHBaud)
      waitcnt(clkfreq / 4 + cnt)
    
      Com.str(@endCmd)
      
      repeat
    
        tempC := getTemperature                            {get the temperture}
        LCD.RawSetPos( $0B )                               {set lcd position}
        LCD.PrintStr(fp.FloatToFormat(temp1, 5, 1))        {float to sting}
        LCD.PrintStr( string(" C" ))                       {display C after temp}
    
        
        Com.str(@readCmd)                                 {Ask for Reading}
        Com.StrIn(@messageBuffer)                         {Getting reading Back}
        LCD.RawSetPos( $00 )                              {set lcd position}  
        LCD.PrintStr( String("Ph"))                       {display "ph"}  
        LCD.RawSetPos( $03 )                              {set lcd position}
        LCD.PrintStr( @messagebuffer)                     {print PH value}
        
        ph := @messageBuffer                               {get PH out of buffer}   { this needs to be float }
    
        LCD.RawSetPos( $40 )                              {set lcd position}  
         LCD.PrintStr( String("Target"))
         LCD.RawSetPos( $4C )                              { diplay to seeon lcd }        
         LCD.PrintStr(fp.FloatToFormat(target_ph, 3, 1))
        
         LCD.RawSetPos( $14 )                              {set lcd position}  
         LCD.PrintStr( String("Actual"))
         LCD.RawSetPos( $20 )                              { diplay to seeon lcd }        
         LCD.PrintStr( ph)
         
         delta := f.FSub(Target_Ph,ph )            { display diference from ph and target_ph  }
    
    
        LCD.RawSetPos( $54 )                              {set lcd position}  
        LCD.PrintStr( String("Diference"))                   
              
        LCD.RawSetPos( $60 )                                             
        LCD.PrintStr( fp.FloatToFormat(delta, 4, 2))
            
        bytefill(@messageBuffer, 0, _BufferSize)
        waitcnt(clkfreq/2  + cnt)
    
    
    
    
    
    
    DAT
    
    endCmd        byte "E", 13, 0
    readCmd       byte "R", 13, 0
    continuousCmd byte "C", 13, 0
    
    PUB getTemperature 
      ow.reset                                              ' send convert temperature command
      ow.writeByte(SKIP_ROM)
      ow.writeByte(CONVERT_T)
    
      repeat                                                ' wait for conversion
        waitcnt(cnt+clkfreq/1000*25)
        if ow.readBits(1)
          quit
    
      ow.reset                                              ' read DS1822 scratchpad
      ow.writeByte(SKIP_ROM)
      ow.writeByte(READ_SCRATCHPAD)
      temp := ow.readByte + ow.readByte << 8                ' read temperature
      temp1 := F.FDiv(F.FFloat(temp), 16.0)                  ' convert to floating point
    
    1024 x 768 - 74K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-02 09:08
    Igor,

    I thought you'd end up wanting to do something like this.

    You probably don't need to use floating point numbers.

    Talke a look at this thread to see what is referred to as "pseudo real" numbers.

    To turn the ASCII characters to a number, take a look at the "StrToBase" method in PST. You'll want to make it a public method. Use base "10" in the conversion. You'll still need to worry about the decimal point. If the decimal point is always in the same place, you can just us a constant multiplier to know how many places your pseudo real number has been shifted.

    So unless you need some complex mathematics, I'd stay away from floating point numbers for now. When you do need FP, Lonesock's "F32" is the object to use. Lawson just fixed a bug in it. The most recent version is here (post #84).
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-02 14:19
    still can't get it working , any code samples ??
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 17:33
    ok , after hour and hour of reading and trying I got the difference problem solved , it,s still in float
    now on my attemt to send the temp to the ph stamp Ive tryed everything again to get they data alined to be send .
    like 23.5 <cr>
    i moved the data in diferent forms , now I got them in the right spot in the data , but there in the wrong format , there decimal number and need to make it a asci .
    can someone please point out wich way I have to look for an anwserrrrrrrrrrrr
    CON
    
       _clkmode = xtal1 + pll16x
       _xinfreq = 5_000_000
    
      buton1 =9                    {input buttons }
      buton2 =10                    {input buttons }
      buton3 =11                    {input buttons }
      buton4 =12                     {input buttons }
      
      RS = 0                         {lcd control}
      RW = 1                         {lcd control}
      E  = 2                         {lcd control}
      DBLow  = 3                      {lcd control}
      DBHigh = 6                      {lcd control}
    
      CR  = 13
      LF  = 10
      PSTClearScreen = 16
    
      tempsensor = 14
      vlotter = 13
    
      zaza = 10.0
      _pHTx = 7                  ' Connected to Rx on pH Stamp
      _pHRx = 8                  ' Connected to Tx on pH Stamp
      _DebugTxPin = 30
      _DebugRxPin = 31
     
      _PhBaud = 38400
      _DebugBaud = 57600
      _BufferSize = 50
    
      Target_PH     = 7.1
                                       
    
      SKIP_ROM          = $CC                               ' 1-wire commands
      READ_SCRATCHPAD   = $BE
      CONVERT_T         = $44
    
      CLS               = $00                               ' clear screen
      HOME              = $01                               ' home
                                   ' carriage return
      DEG               = $B0                               ' degree symbol
       #8, BKSP, TAB
    VAR
    
      byte messageBuffer[_BufferSize]
     long tempc  ,temp1,temp   ,diference,delta    ,ph     ,ph1  ,a,b,c,d,ee,ff,   idx,tc
     byte  nstr[64] 
    OBJ
    
      Com : "Parallax Serial Terminal"                 ' uses two cog
      ow            : "OneWire"
       fp            : "FloatString"
      f             : "FloatMath"   
     
      LCD : "LCD_20x4"
     
      
    PUB Main | localIndex, localAttmpts
    
      ow.start(tempsensor)
      
      LCD.Init( E, RS, RW, DBHigh, DBLow )                            {LCD init}
      LCD.usDelay( 5_000 )                                            {LCD init}
      LCD.Clear
          
     
      waitcnt(clkfreq / 4 + cnt)
    
     
      
      repeat
         
        getTemperature                            {get the temperture}
         
        LCD.RawSetPos( $0B )                               {set lcd position}
        LCD.PrintStr(fp.FloatToFormat(temp1, 5, 1))        {float to sting}
        LCD.PrintStr( string(" C" ))                       {display C after temp}
                                       
       
        byte[@tt][0]:=f.FTrunc(f.fmul(temp1,10.0))/100
        byte[@tt][1]:=f.FTrunc(f.fmul(temp1,10.0))/10 - ((f.FTrunc(f.fmul(temp1,10.0))/100)*10)
        byte[@tt][3]:=f.FTrunc(f.fmul(temp1,10.0))- ((f.FTrunc(f.fmul(temp1,10.0))/10)*10)
        
    
        a:=byte[@tt][0]    
        LCD.RawSetPos( $54 )                              {set lcd position}  
        LCD.Printstr( decx(a,2) )
    
        b:=byte[@tt][1]    
        LCD.RawSetPos( $57 )                              {set lcd position}  
        LCD.Printstr( decx(b,2) )
    
        c:=byte[@tt][2]    
        LCD.RawSetPos( $5A )                              {set lcd position}  
        LCD.Printstr( decx(c,2) )
        
        d:=byte[@tt][3]    
        LCD.RawSetPos( $5F )                              {set lcd position}  
        LCD.Printstr( decx(d,2) )
                  
        ee:=byte[@tt][4]    
        LCD.RawSetPos( $64 )                              {set lcd position}  
        LCD.Printstr( decx(ee,2) )
    
        
         
        waitcnt(clkfreq/2  + cnt)
     
      
    DAT
    
    endCmd        byte "E", 13, 0
    readCmd       byte "r", 13, 0
    continuousCmd byte "C", 13, 0
    tt            byte  "A","5",".","5",13,0
    temp2         long
    PUB getTemperature 
      ow.reset                                              ' send convert temperature command
      ow.writeByte(SKIP_ROM)
      ow.writeByte(CONVERT_T)
    
      repeat                                                ' wait for conversion
        waitcnt(cnt+clkfreq/1000*25)
        if ow.readBits(1)
          quit
    
      ow.reset                                              ' read DS1822 scratchpad
      ow.writeByte(SKIP_ROM)
      ow.writeByte(READ_SCRATCHPAD)
      temp := ow.readByte + ow.readByte << 8                ' read temperature
      temp1 := F.FDiv(F.FFloat(temp), 16.0)                  ' convert to floating point
      
      
    PUB decx(value, digits) | div
    
    '' Returns pointer to zero-padded, signed-decimal string
    '' -- if value is negative, field width is digits+1
    
      clrstr(@nstr, 64)  
      digits := 1 #> digits <# 10
    
      if (value < 0)                                        ' negative value?   
        -value                                              '   yes, make positive
        nstr[idx++] := "-"                                  '   and print sign indicator
    
      div := 1_000_000_000                                  ' initialize divisor
      if digits < 10                                        ' less than 10 digits?
        repeat (10 - digits)                                '   yes, adjust divisor
          div /= 10
      
      value //= (div * 10)                                  ' truncate unused digits
      
      repeat digits
        nstr[idx++] := (value / div + "0")                  ' convert digit to ASCII
        value //= div                                       ' update value
        div /= 10                                           ' update divisor
    
      return @nstr
    
    PRI clrstr(strAddr, size)
    
    ' Clears string at strAddr
    ' -- also resets global character pointer (idx)
    
      bytefill(strAddr, 0, size)                            ' clear string to zeros
      idx~                                                  ' reset index
    

    I also tryed to convert them one bye one ,like in the code below . works wel for the first digit , second digit is a diferent story sadly enough
    PUB  gg 
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 0
         byte[@tt][0]:=48
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 1
         byte[@tt][0]:=49 
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 2
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 3
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 4
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 5
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 6
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 7
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 8
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 9
         byte[@tt][0]:=50 
        
      return
    
    HELLLLLLLLLPPPPPPPPPPPP
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-06 17:46
    You have a floating point number and want that as a string? If so this should do (fp is the FloatString object):
    LCD.Printstr(fp.FloatToString(floating_point_number))
    
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 17:59
    correct, but all the digit's of the temperture (ec 27.5 ) must be send as (byte)asci so for 27.5 ill have to send 50, 55,46,53
    after that I need to send a <cr> so 13
    so the total sting is
    50,55,46,53,13,0

    that's somthing diferent flom that floattostring object or Am i wrong ???
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-06 18:01
    Do you need to send the string "50, 55, 46, 53, 13", or do you need to send those bytes in sequence, because that is what FloatToSTring will do.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 18:02
    DAT
    
    readCmd       byte "r", 13, 0
    
    

    in place of the R . I have to send the temp data
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-06 18:03
    So, yes, send the result of FloatToString followed by char 13.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 18:04
    "50, 55, 46, 53, 13"
    those are the byte's that need to be send

    can't find a way out
  • kuronekokuroneko Posts: 3,623
    edited 2012-02-06 18:08
    The following example - when calling display(temperature) - will basically send out the ASCII characters for "2"(50), "5"(53), "."(46) and "7"(55) followed by a CR(13). It's really not that hard :)
    CON
      _clkmode = XTAL1|PLL16X
      _xinfreq = 5_000_000
    
    CON
      temperature = 25.7
      
    OBJ
      serial: "FullDuplexSerial"
          fs: "FloatString"
          
    PUB null
    
      serial.start(31, 30, %0000, 115200)
      waitcnt(clkfreq*3 + cnt)
      serial.tx(0)
    
      display(PI)
      display(temperature)
    
    PRI display(fpn)
    
      [COLOR="red"]serial.str(fs.FloatToString(fpn))
      serial.tx(13)[/COLOR]
    
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 18:09
    any suggestions on code examples on how to do that ?
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 18:12
    I understand what you mean, tring to figure out how
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-02-06 18:13
    Igor_Rast wrote: »
    PUB  gg 
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 0
         byte[@tt][0]:=48
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 1
         byte[@tt][0]:=49 
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 2
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 3
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 4
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 5
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 6
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 7
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 8
         byte[@tt][0]:=50
      if f.FTrunc(f.fmul(temp1,10.0))/100 == 9
         byte[@tt][0]:=50 
        
      return
    
    Did you notice that your ascii values are 48, 49, 50, 50, 50, 50, 50... ?

    Anyway,
    Com.Str(fp.FloatToString(floating_value_of_temperature))
    Com.Char(13)
    
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-02-06 18:29
    hahah, Yea I noticed it a sec later, forgot to change it in the post.
    but Im verry happy to say
    that your the man of the night
    it work like well
    now it's like this

    with this code I get a temperture compensated reading on my lcd , using a ph stamp of atlas and a ds1820 temp sensor
    also I made some calc to get the dierance between the actual Ph and a target Ph later to set

    THanks allot, Hope the code will help someone one the milestone
    CON
    
       _clkmode = xtal1 + pll16x
       _xinfreq = 5_000_000
    
    
      
      RS = 0                         {lcd control}
      RW = 1                         {lcd control}
      E  = 2                         {lcd control}
      DBLow  = 3                      {lcd control}
      DBHigh = 6                      {lcd control}
    
      CR  = 13
      LF  = 10
      PSTClearScreen = 16
    
      tempsensor = 14
    
    
      
      _pHTx = 7                  ' Connected to Rx on pH Stamp
      _pHRx = 8                  ' Connected to Tx on pH Stamp
      _DebugTxPin = 30
      _DebugRxPin = 31
     
      _PhBaud = 38400
      _DebugBaud = 57600
      _BufferSize = 50
    
      Target_PH     = 7.1
                                       
    
      SKIP_ROM          = $CC                               ' 1-wire commands
      READ_SCRATCHPAD   = $BE
      CONVERT_T         = $44
    
      CLS               = $00                               ' clear screen
      HOME              = $01                               ' home
                                   ' carriage return
      DEG               = $B0                               ' degree symbol
       #8, BKSP, TAB
    VAR
    
      byte messageBuffer[_BufferSize]
     long tempc  ,temp1,temp   ,diference,delta    ,ph     ,ph1
     
    OBJ
    
      Com : "Parallax Serial Terminal"                 ' uses two cog
      ow            : "OneWire"
       fp            : "FloatString"
      f             : "FloatMath"   
     
      LCD : "LCD_20x4"
     
      
    PUB Main | localIndex, localAttmpts
    
      ow.start(tempsensor)
      
      LCD.Init( E, RS, RW, DBHigh, DBLow )                            {LCD init}
      LCD.usDelay( 5_000 )                                            {LCD init}
      LCD.Clear
          
      Com.StartRxTx(_pHRx, _pHTx, 0, _pHBaud)
      waitcnt(clkfreq / 4 + cnt)
    
      Com.str(@endCmd)
      
      repeat
         
        getTemperature                            {get the temperture}
    
        LCD.RawSetPos( $00 )                              {set lcd position}  
        LCD.PrintStr( String("Temperture"))
        LCD.RawSetPos( $0B )                               {set lcd position}
        LCD.PrintStr(fp.FloatToFormat(temp1, 4, 1))        {float to sting}
        LCD.PrintStr( string(" C" ))                       {display C after temp}
            
        Com.str(fp.floattostring(temp1))                                      {Ask for Reading/ sending temp  Thanks "Circuitsoft"}
        com.char(13)
        Com.StrIn(@messageBuffer)                         {Getting reading Back/ readin in messagebuffer}
                            
            
        ph1:=fp.StringToFloat(@messageBuffer)                     {Ph1 = float PH to calculate with} 
        delta := f.FSub(Target_Ph,ph1 )                           {diference = target_ph - PH1  }
    
        LCD.RawSetPos( $40 )                              {set lcd position}  
        LCD.PrintStr( String("Target Ph   7.1 "))
        
        
         LCD.RawSetPos( $14 )                              {set lcd position}  
         LCD.PrintStr( String("Actual Ph"))
         LCD.RawSetPos( $20 )                              { diplay Actual PH on lcd }        
         LCD.PrintStr( @messagebuffer)
          
                     
        LCD.RawSetPos( $54 )                              {set lcd position}  
        LCD.PrintStr( String("Diference"))            
        LCD.RawSetPos( $60 )                                             
        LCD.PrintStr( fp.FloatToFormat(delta, 4, 2))      { display diference from ph and target_ph  }
            
        bytefill(@messageBuffer, 0, _BufferSize)
        waitcnt(clkfreq/2  + cnt)
     
    
    DAT
    
    endCmd        byte "E", 13, 0
    readCmd       byte "r", 13, 0
    continuousCmd byte "C", 13, 0
    tt            byte  "2","5",".","5",13,0
    temp2         byte
    PUB getTemperature 
      ow.reset                                              ' send convert temperature command
      ow.writeByte(SKIP_ROM)
      ow.writeByte(CONVERT_T)
    
      repeat                                                ' wait for conversion
        waitcnt(cnt+clkfreq/1000*25)
        if ow.readBits(1)
          quit
    
      ow.reset                                              ' read DS1822 scratchpad
      ow.writeByte(SKIP_ROM)
      ow.writeByte(READ_SCRATCHPAD)
      temp := ow.readByte + ow.readByte << 8                ' read temperature
      temp1 := F.FDiv(F.FFloat(temp), 16.0)                  ' convert to floating point
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-07 10:56
    Does your temperature sensor return a floating point value?

    It looks like the only time you're using floating point math is to multiply and divide (which work fine using integer math). I still think it would be easier to convert the temperature to a pseudo real number (by multiplying it by a set amount and then use the "FRound" or "FTrunc" method to convert it to an integer) and then do the rest of the calculations in pseudo real integers.

    You can then use the "DecPoint" method I linked to, to send the number to the pH Stamp.

    If you stay with floating point, use the method kuroneko showed you.
Sign In or Register to comment.