Shop OBEX P1 Docs P2 Docs Learn Events
Sharing Variables tru Diferent COg,s SHT-11 sensiron sensor help . can't get the VAR' — Parallax Forums

Sharing Variables tru Diferent COg,s SHT-11 sensiron sensor help . can't get the VAR'

Igor_RastIgor_Rast Posts: 357
edited 2011-09-16 08:01 in Propeller 1
Im trying again to get the variables from anther cog.
wanted to let another cog run the program to get the temp and Rh measurements,
if I run it in a single Cog all goes Ok , if ill try to split it up so I can have one cog taking the readings.
and the main cog just looks at the varables and displays them on the LCD,
this because the main cog is handeling more processes and it gets a bit slow if i let the same cog do the reading .
hope someone could point out where my code goes wrong ,
im getting only a 0 display
igor
CON

   _clkmode = xtal1 + pll16x
   _xinfreq = 5_000_000

  RS = 25                         {lcd control}
  RW = 26                         {lcd control}
  E  = 27                         {lcd control}
  DBLow  = 0                      {lcd control}
  DBHigh = 3                      {lcd control}

  SHT_DATA      = 13                                    ' SHT-11 data pin
  SHT_CLOCK     = 15                                    ' SHT-11 clock pin

  CLS         = $0                                      ' clear screen
  CR          = $D                                      ' carriage return
  Deg         = $B0
OBJ
 
  LCD : "LCD_20x4"                                                         {LCD controler}
  debug : "FullDuplexSerial"  
  sht           : "Sensirion_full"
  fp            : "FloatString"
  f             : "Float32"
   SN    : "Simple_Numbers" 
  
VAR      
long stack1[128],idx,tc
byte  nstr[64]     
word tempC1,tempC2,tempC3,rh1,rh2,rh3

PUB Main

    f.start

    LCD.Init( E, RS, RW, DBHigh, DBLow )                           
    LCD.usDelay( 5_000 )                                            
    LCD.Clear

    cognew(tempcontrol,@stack1)

     repeat
       print_temp 
       waitcnt(clkfreq + cnt)
PUB print_temp
     
    LCD.RawSetPos( $1C )                    
    LCD.PrintStr(tempC2)
    LCD.PrintStr( string(" C" ))

    LCD.RawSetPos( $5C )                   
    LCD.PrintStr( rh2 )
    LCD.PrintStr( string(" %" ))

    return
PUB tempcontrol

    sht.start(14,15)
    f.start
    
    repeat    
     
         tempC1 := celsius(f.FFloat(sht.readTemperature))     {floating point raw measurement temp}
         tempC2 := fp.FloatToFormat(tempC1, 2, 0)               { string for the display}
         tempC3 :=f.FTrunc(tempC1)                              { integer to calculate/use  }

          rh1 := humidity(tempC1, f.FFloat(sht.readHumidity))   {floating poitn ram measurement RH }
          rh2 := fp.FloatToFormat(rh1, 2, 0)                    { string for the display}
          rh3 :=f.FTrunc(rh1)
          waitcnt(clkfreq + cnt)

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-09-14 01:25
    What FloatString object are you using? Mine doesn't have a FloatToFormat method (PropTool 1.3). Apart from that, floating point numbers require a long for storage, a word is not enough (tempC1 and rh1 look suspicious).
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-09-14 22:22
    please attach your complete code as an archive created with the arhcive function of the propellertool to a posting
    keep the questions coming
    best regards

    Stefan
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-09-15 07:55
    sensiron - Archive [Date 2011.09.15 Time 16.50].zip

    OK ,so there the Archive file .
    ive changed the word to a long , now it gets the values, but i get or temp printed to both temp and rh or the other way around .

    they overlap or somthing .

    what im tring to get is a program so I can ready multiple sensors and store the values to use them , so 2 sensor's

    the sensors share the clock line , and both have a independant data line
    hope this is enough info to get the problem sorted

    hope to hear soon
    igor
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-15 18:07
    The issue is with how you use the FloatString object. For number to string conversion it uses an internal buffer. Getting the address is all fine but you then have to print (i.e. use) the string before you do the next conversion (which re-uses the buffer). An easy fix would be to copy the string into a display array, e.g.
    VAR
      byte  temperature[64]
    
      ...
          tempC2 := fp.FloatToFormat(tempC1, 2, 0)               { string for the display}
          bytemove(@temperature{0}, tempC2, strsize(tempC2) +1)
          tempC3 :=f.FTrunc(tempC1)                              { integer to calculate/use  }
    
    and then display the string from there. Temperature and humidity obviously need separate arrays.
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-09-16 00:25
    Kuroneko , could you archive the code the way you mean for me,
    made the changes , but it doen's realy do that , tha display value is nog good
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-16 00:48
    Attached (only the primary object file). I left the debug output code in there (commented out) as I don't have LCD h/w. I also faked temperature output which increases by 1 degree every time it's called (wraps after 10 calls) and I see reasonable output in the terminal.

    Ideally you just store temperature and humidity as is and let the display code do the conversion (which voids the requirement for separate buffers). Meaning your display code will look something like this:
    PUB print_temp
         
      LCD.RawSetPos($1C)                      
      LCD.PrintStr([COLOR="orange"]fp.FloatToFormat(tempC1, 2, 0)[/COLOR])
      LCD.PrintStr(string(" C"))
    
      LCD.RawSetPos($5C)                     
      LCD.PrintStr([COLOR="orange"]fp.FloatToFormat(rh1, 2, 0)[/COLOR])
      LCD.PrintStr(string(" %"))
    
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-09-16 07:28
    Kuroneko again you save my day, not realy understanding it completly , but i'm gonna find it out soon ,
    the buffer issue was indeed the probem , anyway

    thanks allot for the help , sure helped me out

    I was wondering if maybe you had any advise info on how to create a frequentie controler with the propeller to control a single fase 230 volt ac motor ,
    sniffing around for some time but can't anyhing concrete to replicate or so . maybe you got any ideas

    igor
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-16 07:38
    Igor_Rast wrote: »
    I was wondering if maybe you had any advise info on how to create a frequentie controler with the propeller to control a single fase 230 volt ac motor, sniffing around for some time but can't anyhing concrete to replicate or so . maybe you got any ideas
    Sorry, not my area of expertise unless you could extract the s/w part. I'm sure others will chime in. Anyway, glad you made progress.
  • Igor_RastIgor_Rast Posts: 357
    edited 2011-09-16 08:01
    ok , no problem ,
    where im there and I get stuck again , ill give you a peep

    THANKSS
Sign In or Register to comment.