Shop OBEX P1 Docs P2 Docs Learn Events
fastspin Basic C class dht22 — Parallax Forums

fastspin Basic C class dht22

I decided to try out using the dht22.c program as a class for the fastspin Basic program shown below. As you can see the compile came back with errors. The strange part is, if I comment out 'temp = dht.dht22_getTemp(1)' and 'humid = dht.dht22_getHumidity()', then it compiles without errors. Do not know why it cannot find dht22_getTemp() and dht22_getHumidity(). I guess I need a short tutorial on how to do this correctly.

Ray
"F:/fastspin/spin2gui/bin/fastspin" -l -O2 -L "./include" "F:/flexbasic/test3/test3.bas"
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
Version 3.9.25 Compiled on: Apr 14 2019
test3.bas
|-dht22.c
warning: : Preprocessor warnings:
F:/flexbasic/test3/dht22.h:123: warning: End of file with no newline, supplemented newline
*/
from F:/flexbasic/test3/dht22.c: 16: #include "dht22.h"
F:/flexbasic/test3/dht22.c:176: warning: End of input with no newline, supplemented newline
*/

F:/flexbasic/test3/test3.bas(9) error: unknown identifier dht22_gettemp in class dht22
F:/flexbasic/test3/test3.bas(9) error: dht22_gettemp is not a member of dht22
F:/flexbasic/test3/test3.bas(12) error: unknown identifier dht22_gethumidity in class dht22
F:/flexbasic/test3/test3.bas(12) error: dht22_gethumidity is not a member of dht22
F:/flexbasic/test3/test3.bas(9) error: unknown identifier dht22_gettemp in class dht22
F:/flexbasic/test3/test3.bas(9) error: dht22_gettemp is not a member of dht22
F:/flexbasic/test3/test3.bas(9) error: unknown identifier dht22_gettemp in class dht22
F:/flexbasic/test3/test3.bas(9) error: dht22_gettemp is not a member of dht22
F:/flexbasic/test3/test3.bas(12) error: unknown identifier dht22_gethumidity in class dht22
F:/flexbasic/test3/test3.bas(12) error: dht22_gethumidity is not a member of dht22
F:/flexbasic/test3/test3.bas(12) error: unknown identifier dht22_gethumidity in class dht22
F:/flexbasic/test3/test3.bas(12) error: dht22_gethumidity is not a member of dht22
child process exited abnormally
'test3.bas

dim dht as class using "dht22.c"

dim as single temp,humid

print "Testing..."
dht.dht22_read(2)
temp = dht.dht22_getTemp(1)
print temp;
dht.dht22_read(2)
humid = dht.dht22_getHumidity()
print humid

dht22.c
/**
 * @file dht22.h
 *
 * @author Matthew Matz
 *
 * @version 0.6
 *
 * @copyright
 * Copyright (C) Parallax, Inc. 2017. All Rights MIT Licensed.
 *
 * @brief This Propeller C library was created for the DHT22 temperature 
 * and humidity sensor module.
 */

#include <propeller.h>
#include "dht22.h"

static int dht_timeout[32];
static int dht_last_temp, dht_last_humidity, dht_timeout_ignore;


void dht22_set_timeout_ignore(int dht_pin, char ignore_timeout) {
  
  // Set up a pin mask
  int dhtpm = (1 << dht_pin);

  // Set or clear the bit for the specified pin
  if (ignore_timeout) {
    dht_timeout_ignore |= dhtpm;
  } else {
    dht_timeout_ignore &= ~dhtpm;
  }
}


int dht22_getTemp(char temp_units) {
  int tt = dht_last_temp;
  if (temp_units == KELVIN)
    tt += 2732;
  else if (temp_units == FAHRENHEIT)
    tt = tt * 9 / 5 + 320;
  
  return tt;
}


int dht22_getHumidity() {
  
  return dht_last_humidity;
}


char dht22_read(int dht_pin) {
  
  // Check to make sure the pin is valid
  if(dht_pin >= 0 && dht_pin < 32) { 
    
    // Set up a pin mask
    int dhtpm = (1 << dht_pin);
    
    // Has it been less than 0.5 seconds since this function was last called?
    if (CNT - dht_timeout[dht_pin] < CLKFREQ/2 && dht_timeout[dht_pin] != 0 && !(dht_timeout_ignore & dhtpm))
      waitcnt(dht_timeout[dht_pin] + CLKFREQ/2);  // If so, wait until 0.5 s has elapsed.
    
    // Set up variables to hold incoming data
    int dhtp[44];
    int dhtc = 0, dhtk = 0, dhts = 0, dhto = 0, dhth = 0, dhtt = 0, dhte = 0;
    
    // Pull the data pin low
    OUTA &= ~dhtpm;
    DIRA |= dhtpm;
    
    // Wait 18 ms
    waitcnt(CLKFREQ/55 + CNT);  
  
    // Set the data pin to an input
    DIRA &= ~dhtpm;
    
    // Set a 2 second timer for the pulse measurements to prevent lockup
    dhto = CNT;
  
    // Set up a state monitor
    int dhst = 0;
    
    // After each full pulse, store the system clock in an 
    // array until 42 measurements are recorded (1 start pulse +
    // 5 bytes of data)
    // Loops enough times to capture data if the sensor is 
    // operating properly
    for (int j = 0; j < CLKFREQ / 2000; j++) {
      if (!(INA & dhtpm) && !dhst)
        dhst = 1;
      if ((INA & dhtpm) && dhst) {
        dhst = 0;
        dhtp[dhtc] = CNT;
        if (dhtc < 44) {
          dhtc++;
        }          
      }
    }
  
    // Measure the length of each pulse to determine if it's a 0 or 1.
    // Bytes 1 & 2 are % relative humidity
    for (dhtc = 2; dhtc < 18; dhtc++) {
      dhth <<= 1;
      dhth |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
    }
   
    // Bytes 3 & 4 are temperature (Celsius)
    for (dhtc = 18; dhtc < 34; dhtc++) {
      dhtt <<= 1;
      dhtt |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
    }
  
    // Byte 5 is a additive checksum
    for (dhtc = 34; dhtc < 42; dhtc++) {
      dhtk <<= 1;
      dhtk |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
    }
    
    // The MSB of the temp is a sign bit, but it's not 2's-compliment...
    // So determine it, then remove it
    dhts = dhtt & 32768;
    dhtt &= 32767;
    
    // If the temp is negative, multiply it by -1
    dhtt *= (dhts ? -1 : 1);
    
    // Calculate the checksum
    dhte = (((dhth >> 8) & 255) + (dhth & 255) + ((dhtt >> 8) & 255) + (dhtt & 255)) & 255;
    
    // Save the result into a single int
    // Bits 0-15: (Celsius Temp * 20) + 100
    // Bits 16-31: (Humidity)
    // Checksum
    
    // Save the temp and humidity into the passed in variables
    // Convert to Farenheiht if requested
    dht_last_humidity = dhth;
    dht_last_temp = dhtt;
        
    // Save the system clock so that the sensor 
    // is not queried again for at least .5 seconds
    dht_timeout[dht_pin] = CNT;
    
    // Return true if the checksum matches
    return dhte == dhtk;
    
  } else {
    
    // Invalid pin
    return 0;    
  }    
}

/**
 * TERMS OF USE: MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

dht22.h
/**
 * @file dht22.h
 *
 * @author Matthew Matz
 *
 * @version 0.6
 *
 * @copyright
 * Copyright (C) Parallax, Inc. 2017. All Rights MIT Licensed.
 *
 * @brief This Propeller C library was created for the DHT22 temperature 
 * and humidity sensor module.
 */


#ifndef  __DHT22_SENSOR_H__                                  // Prevents duplicate
#define  __DHT22_SENSOR_H__                                  // declarations

#if defined(__cplusplus)                                     // If compiling for C++
extern "C" {                                                 // Compile for C
#endif


// Units of temperature
#ifndef  CELSIUS 
#define  CELSIUS            0
#endif

#ifndef  FAHRENHEIT 
#define  FAHRENHEIT         1
#endif

#ifndef  KELVIN 
#define  KELVIN             2
#endif


/**
 * @brief Triggers a reading of the temperature and relative humidity from the sensor module.
 *
 * @details This function instructs the temperature and humidity sensor module  
 * to take a reading.  
 *
 * @note The sensor can be read every 500ms.  If this function is called
 * before 500ms from the previous call has elapsed, the function waits unless the
 * dht22_set_timeout_ignore() function was used to instruct modules on that pin to
 * ignore the 0.5 second minimum timeout.
 * 
 * @param dht_pin defines which Propeller MCU I/O pin the sensor is attached to.  
 * Requires a 10 kOhm pullup resistor to 3.3V when connecting to the Propeller MCU.
 *
 * @returns 1 if a valid checksum was recieved, 0 if the checksum is invalid.
 */

char dht22_read(int dht_pin);


/**
 * @brief The function is used to set or clear an ignore timeout instruction for
 * modules connected to the specified pin.
 *
 * @param dht_pin defines which pin the sensor is attached to.
 *
 * @param ignore_timeout when true (1), the function instructs the Propeller MCU to
 * ignore the protective timeout that prevents the sensor from being read before 
 * it is ready.  This parameter is set to false (0) by default.
 */

void dht22_set_timeout_ignore(int dht_pin, char ignore_timeout);


/**
 * @brief Retrieves the last temperature reading made by the dht22_read() function.
 *
 * @param temp_units allows the temperature unit to be specified in (0) Celsius,
 * (1) Fahrenheit, or (2) Kelvin.
 *
 * @returns the temperature read in degree-tenths of the unit specified.
 */

int dht22_getTemp(char temp_units);


/**
 * @brief Retrieves the last humidity reading made by the dht22_read() function.
 *
 * @returns the last relative humidity read in tenths of a percent.
 */

int dht22_getHumidity();



#if defined(__cplusplus)                     
}                                             // End compile for C block
#endif
/* __cplusplus */

#endif                                        // End prevent duplicate forward
/* __DHT22_SENSOR_H__ */                      // declarations block 


/**
 * TERMS OF USE: MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

Comments

  • The problem is that Spin and BASIC are case insensitive (basically all identifiers are translated to lower case before use) but C is case sensitive. I think you can fix your problem by changing all the function names in dht22.c and dht22.h to be all lower case.
  • This was a quick and dirty test run of the program below. After changing the functions names to lower case as suggested, it compiled and executed without errors. I did a compile using the Full Optimization mode and the results:
    Program size is 5588 bytes.
    WOW, I guess fastspin Optimization really likes C code.

    Ray


    'test3.bas
    '
    ' April 28, 2019
    '
    '
    
    dim dht as class using "dht22.c"
    
    dim as single temp,humid
    
    waitcnt(getcnt() + 10_000_000)  ' Wait for terminal screen to catch up.
    
    
    print "Testing..."
    
    do
    	dht.dht22_read(2)
    	temp = dht.dht22_getTemp(1)  ' 1 = *F
    	print temp*.10;"  ";
    	dht.dht22_read(2)
    	humid = dht.dht22_getHumidity()
    	print humid*.10
    	pausems 3000
    loop
    
    end
    
  • I just ran fsrw26.spin, using my new setup, and it fails when you use any optimization. Anybody know where the SimpleIDE C version of fsrw can be found. I would like to try running that with full optimization, just to see what the results would be.

    Ray
  • I improved the dht22 program with a user I/O component. Below I included the changed .c and .h files, I hope the notes I made are good enough to comply with the Parallax standards. If not, some suggestions would be beneficial.

    I noticed when compiling, I am getting a Preprocessor warning, how do I fix that.

    I also noticed that when the program just had a simple do .. loop, the program size was, when optimized, 5588 bytes. Now with just an if loop added, it is up to 9576 bytes optimized. What are some of the big ticket, code wise additions, to be aware of?

    The dht22 program was a fairly simple conversion to make to have it run with fastspin Basic. I just did a quick test to see how the SimpleIDE C code for datetime would work. That is a lot more complicated, because it requests a lot of different code that is all over the place. Not sure how to even gather and place it in an area where fastspin could find it all. Will have to do some more experimentation with that one.

    Ray
    'test3.bas
    '
    ' April 28, 2019
    '
    ' This code operates the CM2302, also known as, AM2302, Temperature
    ' Humidity module.
    ' Now uses dht22_fs.c and dht22_fs.h files do to some changes in the
    ' code. Changes were made to comply with fastspin Basic requirements.
    '
    
    dim dht as class using "dht22_fs.c"
    
    dim as single temp,humid
    dim as string inBuff
    
    waitcnt(getcnt() + 10_000_000)  ' Wait for terminal screen to catch up.
    
    
    print "Type 'help' to view program menu."
    
    do
    	print "> ";
    	input inBuff
    	if inBuff = "quit" then
    		print "Program end!"
    		exit do
    	else if inBuff = "help" then
    		menu()
    	else if inBuff = "htemp" then
    		htemp()
    	else
    		print "Do not understand!"
    	end if
    
    loop
    
    end
    
    sub htemp
    	dht.dht22_read(2)
    	temp = dht.dht22_getTemp(1)  ' 1 = *F
    	print "Temperature: ";(temp*.10);" *F  ";
    	humid = dht.dht22_getHumidity()
    	print "Humidity: ";(humid*.10);" %"
    	pausems 2000
    end sub
    
    sub menu
    	print "Menu"
    	print "help - Show the menu."
    	print "quit - Program end."
    	print "htemp - Show temperature(*F) and humidity."
    end sub
    
    F:\fastspin\spin2gui\bin\fastspin -l -b -O2 "test3.bas" (in directory: F:\flexbasic\test3)
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 3.9.25 Compiled on: Apr 14 2019
    test3.bas
    |-dht22_fs.c
    readdata.spin
    test3.pasm
    Done.
    Program size is 9576 bytes
    warning: : Preprocessor warnings:
    F:/flexbasic/test3/dht22_fs.c:183: warning: End of input with no newline, supplemented newline
    */
    Compilation finished successfully.

    dht22_fs.c
    /**
     * @file dht22_fs.c
     *
     * @author Matthew Matz
     *
     * @version 0.6
     *
     * @copyright
     * Copyright (C) Parallax, Inc. 2017. All Rights MIT Licensed.
     *
     * @brief This Propeller C library was created for the DHT22 temperature 
     * and humidity sensor module.
     *
     * April 28, 2019
     * Changed file name from dht22.c to dht22_fs.c.
     * Changed file name form dht22.h to dht22_fs.h.
     * Changed function names to lower case.
     * Made to work with fastspin Basic.
     * R Sadeika
     */
    
    #include <propeller.h>
    #include "dht22_fs.h"
    
    static int dht_timeout[32];
    static int dht_last_temp, dht_last_humidity, dht_timeout_ignore;
    
    
    void dht22_set_timeout_ignore(int dht_pin, char ignore_timeout) {
      
      // Set up a pin mask
      int dhtpm = (1 << dht_pin);
    
      // Set or clear the bit for the specified pin
      if (ignore_timeout) {
        dht_timeout_ignore |= dhtpm;
      } else {
        dht_timeout_ignore &= ~dhtpm;
      }
    }
    
    
    int dht22_gettemp(char temp_units) {
      int tt = dht_last_temp;
      if (temp_units == KELVIN)
        tt += 2732;
      else if (temp_units == FAHRENHEIT)
        tt = tt * 9 / 5 + 320;
      
      return tt;
    }
    
    
    int dht22_gethumidity() {
      
      return dht_last_humidity;
    }
    
    
    char dht22_read(int dht_pin) {
      
      // Check to make sure the pin is valid
      if(dht_pin >= 0 && dht_pin < 32) { 
        
        // Set up a pin mask
        int dhtpm = (1 << dht_pin);
        
        // Has it been less than 0.5 seconds since this function was last called?
        if (CNT - dht_timeout[dht_pin] < CLKFREQ/2 && dht_timeout[dht_pin] != 0 && !(dht_timeout_ignore & dhtpm))
          waitcnt(dht_timeout[dht_pin] + CLKFREQ/2);  // If so, wait until 0.5 s has elapsed.
        
        // Set up variables to hold incoming data
        int dhtp[44];
        int dhtc = 0, dhtk = 0, dhts = 0, dhto = 0, dhth = 0, dhtt = 0, dhte = 0;
        
        // Pull the data pin low
        OUTA &= ~dhtpm;
        DIRA |= dhtpm;
        
        // Wait 18 ms
        waitcnt(CLKFREQ/55 + CNT);  
      
        // Set the data pin to an input
        DIRA &= ~dhtpm;
        
        // Set a 2 second timer for the pulse measurements to prevent lockup
        dhto = CNT;
      
        // Set up a state monitor
        int dhst = 0;
        
        // After each full pulse, store the system clock in an 
        // array until 42 measurements are recorded (1 start pulse +
        // 5 bytes of data)
        // Loops enough times to capture data if the sensor is 
        // operating properly
        for (int j = 0; j < CLKFREQ / 2000; j++) {
          if (!(INA & dhtpm) && !dhst)
            dhst = 1;
          if ((INA & dhtpm) && dhst) {
            dhst = 0;
            dhtp[dhtc] = CNT;
            if (dhtc < 44) {
              dhtc++;
            }          
          }
        }
      
        // Measure the length of each pulse to determine if it's a 0 or 1.
        // Bytes 1 & 2 are % relative humidity
        for (dhtc = 2; dhtc < 18; dhtc++) {
          dhth <<= 1;
          dhth |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
        }
       
        // Bytes 3 & 4 are temperature (Celsius)
        for (dhtc = 18; dhtc < 34; dhtc++) {
          dhtt <<= 1;
          dhtt |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
        }
      
        // Byte 5 is a additive checksum
        for (dhtc = 34; dhtc < 42; dhtc++) {
          dhtk <<= 1;
          dhtk |= (dhtp[dhtc] - dhtp[dhtc-1] > CLKFREQ/9800);
        }
        
        // The MSB of the temp is a sign bit, but it's not 2's-compliment...
        // So determine it, then remove it
        dhts = dhtt & 32768;
        dhtt &= 32767;
        
        // If the temp is negative, multiply it by -1
        dhtt *= (dhts ? -1 : 1);
        
        // Calculate the checksum
        dhte = (((dhth >> 8) & 255) + (dhth & 255) + ((dhtt >> 8) & 255) + (dhtt & 255)) & 255;
        
        // Save the result into a single int
        // Bits 0-15: (Celsius Temp * 20) + 100
        // Bits 16-31: (Humidity)
        // Checksum
        
        // Save the temp and humidity into the passed in variables
        // Convert to Farenheiht if requested
        dht_last_humidity = dhth;
        dht_last_temp = dhtt;
            
        // Save the system clock so that the sensor 
        // is not queried again for at least .5 seconds
        dht_timeout[dht_pin] = CNT;
        
        // Return true if the checksum matches
        return dhte == dhtk;
        
      } else {
        
        // Invalid pin
        return 0;    
      }    
    }
    
    /**
     * TERMS OF USE: MIT License
     *
     * Permission is hereby granted, free of charge, to any person obtaining a
     * copy of this software and associated documentation files (the "Software"),
     * to deal in the Software without restriction, including without limitation
     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     * and/or sell copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     * DEALINGS IN THE SOFTWARE.
     */
    [/CODE
    dht22_fs.h
    [code]
    /**
     * @file dht22_fs.h
     *
     * @author Matthew Matz
     *
     * @version 0.6
     *
     * @copyright
     * Copyright (C) Parallax, Inc. 2017. All Rights MIT Licensed.
     *
     * @brief This Propeller C library was created for the DHT22 temperature 
     * and humidity sensor module.
     * April 28, 2019
     * Changed file name from dht22.c to dht22_fs.c.
     * Changed file name form dht22.h to dht22_fs.h.
     * Changed function names to lower case.
     * Made to work with fastspin Basic
     * R Sadeika
     */
    
    
    #ifndef  __DHT22_SENSOR_H__                                  // Prevents duplicate
    #define  __DHT22_SENSOR_H__                                  // declarations
    
    #if defined(__cplusplus)                                     // If compiling for C++
    extern "C" {                                                 // Compile for C
    #endif
    
    
    // Units of temperature
    #ifndef  CELSIUS 
    #define  CELSIUS            0
    #endif
    
    #ifndef  FAHRENHEIT 
    #define  FAHRENHEIT         1
    #endif
    
    #ifndef  KELVIN 
    #define  KELVIN             2
    #endif
    
    
    /**
     * @brief Triggers a reading of the temperature and relative humidity from the sensor module.
     *
     * @details This function instructs the temperature and humidity sensor module  
     * to take a reading.  
     *
     * @note The sensor can be read every 500ms.  If this function is called
     * before 500ms from the previous call has elapsed, the function waits unless the
     * dht22_set_timeout_ignore() function was used to instruct modules on that pin to
     * ignore the 0.5 second minimum timeout.
     * 
     * @param dht_pin defines which Propeller MCU I/O pin the sensor is attached to.  
     * Requires a 10 kOhm pullup resistor to 3.3V when connecting to the Propeller MCU.
     *
     * @returns 1 if a valid checksum was recieved, 0 if the checksum is invalid.
     */
    
    char dht22_read(int dht_pin);
    
    
    /**
     * @brief The function is used to set or clear an ignore timeout instruction for
     * modules connected to the specified pin.
     *
     * @param dht_pin defines which pin the sensor is attached to.
     *
     * @param ignore_timeout when true (1), the function instructs the Propeller MCU to
     * ignore the protective timeout that prevents the sensor from being read before 
     * it is ready.  This parameter is set to false (0) by default.
     */
    
    void dht22_set_timeout_ignore(int dht_pin, char ignore_timeout);
    
    
    /**
     * @brief Retrieves the last temperature reading made by the dht22_read() function.
     *
     * @param temp_units allows the temperature unit to be specified in (0) Celsius,
     * (1) Fahrenheit, or (2) Kelvin.
     *
     * @returns the temperature read in degree-tenths of the unit specified.
     */
    
    int dht22_gettemp(char temp_units);
    
    
    /**
     * @brief Retrieves the last humidity reading made by the dht22_read() function.
     *
     * @returns the last relative humidity read in tenths of a percent.
     */
    
    int dht22_gethumidity();
    
    
    
    #if defined(__cplusplus)                     
    }                                             // End compile for C block
    #endif
    /* __cplusplus */
    
    #endif                                        // End prevent duplicate forward
    /* __DHT22_SENSOR_H__ */                      // declarations block 
    
    
    /**
     * TERMS OF USE: MIT License
     *
     * Permission is hereby granted, free of charge, to any person obtaining a
     * copy of this software and associated documentation files (the "Software"),
     * to deal in the Software without restriction, including without limitation
     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     * and/or sell copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     * DEALINGS IN THE SOFTWARE.
     */
    
    
  • pmrobertpmrobert Posts: 669
    edited 2019-04-29 14:36
    The preprocessor warning means that the last line of your source doesn't have a CR/LF at it's end. Just go to the last line of your source, hit return and save. The warning will disappear. Eric may be looking for a true newline (ASCII 10) which is part of the CR/LF (13 and 10) sequence a return sends on Windows. It's similar but not identical in *nix and yet again on Mac. I included this last for completeness. If you add a lower case '-l' (L) to the fastspin command line it will generate a listing file which will contain the PASM that is actually assembled and loaded. Your source code is in that file as comments and you can see what statements generate what PASM sequences, etc. If your source file is "foo.bas" the listing file will be "foo.lst". Hope that helps!

    Mike R.

    Addendum: Also, if you haven't read the .md files included with fastspin you'll find them interesting. They're terse but full of hints and comments on how this pretty cool compiler works and interacts with interlanguage type operations such as you're contemplating.
  • Thanks Mike, I did a CR in one of the files, but did not realize that the other file needed a CR also.

    This fastspin is a very interesting tool, he has a lot of things going on under the hood. The other thing that I noticed was, because fastspin produces a .pasm file, you could almost use that to learn some things about PASM. The only problem that I see, that would confuse things for me, is the LMM stuff that shows up in the file listing. I know that, in the Propeller manual, there is some PASM code for flashing a pin, hopefully you would have an LED attached, to see the code come to life. To bad there isn't a switch to turn on/off the LMM, that way you could produce some code, and check out some really simple routines.

    I am thinking along the lines of using fastspin Basic to produce some prototype code, and then you could review the .pasm file to see if and where you could tweak the code, I think. Since I do not think in PASM, I think producing a line in Basic like 'high(1)' to turn on an LED, and then look at the PASM code, to see what it took do that, might be a way to learn PASM, for me anyway.

    Ray
  • pmrobertpmrobert Posts: 669
    edited 2019-04-29 17:30
    See below - giving it a --code=cog argument should disable LMM! Edit: That doesn't appear to work for C as the code sizes haven't changed and the listings are identical. I'm sure will have something to add here. I don't know if it may work for BASIC as I don't use it. Give it a try and see what happens.
    usage: fastspin [options] filename.spin | filename.bas
      [ -h ]              display this help
      [ -L or -I <path> ] add a directory to the include path
      [ -o <name> ]      set output filename to <name>
      [ -b ]             output binary file format
      [ -e ]             output eeprom file format
      [ -c ]             output only DAT sections
      [ -l ]             output DAT as a listing file
      [ -f ]             output list of file names
      [ -q ]             quiet mode (suppress banner and non-error text)
      [ -p ]             disable the preprocessor
      [ -D <define> ]    add a define
      [ -u ]             ignore for openspin compatibility (unused method elimination always enabled)
      [ -2 ]             compile for Prop2
      [ -O# ]            set optimization level:
              -O0 = no optimization
              -O1 = basic optimization
              -O2 = all optimization
      [ -H nnnn ]        set starting hub address
      [ -E ]             skip initial coginit code (usually used with -H)
      [ -w ]             compile for COG with Spin wrappers
      [ -C ]             enable case sensitive mode
      [ --code=cog ]     compile for COG mode instead of LMM  <<<<<<============ Here you go - LMM disable!
      [ --fcache=N ]     set FCACHE size to N (0 to disable)
      [ --fixedreal ]    use 16.16 fixed point in place of floats
      [ --lmm=xxx ]      use alternate LMM implementation for P1
               xxx = orig uses original fastspin LMM
               xxx = slow uses traditional (slow) LMM
    
  • There are actually 2 ways to disable LMM: --code=cog, and -w. The "-w" (generate Spin wrapper) is intended for creating OpenSpin/PropTool compatible objects that will run in their own COG. See doc/SpinPasmIntegration.md for details.
Sign In or Register to comment.