Jump to content

arre

Members
  • Content Count

    6
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    arre got a reaction from bluehash in DHT11 temperature & humidity sensor code snippet   
    Hi, 
     
    Thought I'd share a small code snippit I built to interface succesfully with the DHT11 temp & humidity sensor (4 bucks on ebay):
    #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/pin_map.h" #include "driverlib/gpio.h" #include "driverlib/systick.h" #include "driverlib/timer.h" int temp; int humidity; inline long WaitUntilPinState(int clockMhz, long pinbase, long pin, long timerbase, long timer, int previousstate, int usec) { // Debounce really not needed unless you have huge noise, but just in case (the processor is fast enough) #define DEBOUNCEMATCHES 5 long timermax; long timerval; int matches = 0; TimerDisable(timerbase, timer); TimerConfigure(timerbase, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT); TimerLoadSet(timerbase, timer, usec*clockMhz); timermax = TimerValueGet(timerbase, timer); timerval = timermax; TimerEnable(timerbase, timer); while(matches < DEBOUNCEMATCHES){ /* Wait for DHT to pull down */ if( GPIOPinRead(pinbase, pin) > 0 != previousstate > 0) { matches++; } else { matches = 0; } timerval = TimerValueGet(timerbase, timer); if(!timerval) timerval = 1; /* make sure we never return 0 by mistake */ if (timerval==timermax){ return 0; } } return timerval; } int ReadDHT() { // bit buffers & timeout char bitcount; char byte; char bits[5] = {0,0,0,0,0}; unsigned int bitints[6]; long timerval; int clockMhz; #define MY_PIN_PERIPH SYSCTL_PERIPH_GPIOE #define MY_PIN_PORTBASE GPIO_PORTE_BASE #define MY_PINNR GPIO_PIN_1 #define MY_TIMER_PERIPH SYSCTL_PERIPH_TIMER0 #define MY_TIMERBASE TIMER0_BASE #define MY_TIMER TIMER_B clockMhz = SysCtlClockGet() / 1000000; /* Configure hardware counter to check how long we are looping */ SysCtlPeripheralEnable(MY_TIMER_PERIPH); TimerConfigure(MY_TIMERBASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT); // request reading SysCtlPeripheralEnable(MY_PIN_PERIPH); GPIOPinTypeGPIOOutput(MY_PIN_PORTBASE, MY_PINNR); GPIOPinWrite(MY_PIN_PORTBASE, MY_PINNR, 0x0); // #loops = loops_per_us*time_in_us = time in us * loops/us = time_in_us *(clockfreq/10000000) SysCtlDelay(30000*clockMhz); // -> 30 ms /////// SET PIN HIGH (putting it to input will do) GPIOPinTypeGPIOInput(MY_PIN_PORTBASE, MY_PINNR); SysCtlDelay(10*clockMhz); /* Wait for DHT pull down */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,50)) return 0; /* Wait for dummy up */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,0,90)) return 0; /* Wait for dummy down */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,90)) return 0; // start receiving 40 bits char i; bitcount = 7; byte = 0; for (i=0; i < 40; i++) { /* Wait for pull up */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,0,60)) return 0; /* Wait for pull down and count */ timerval = WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,90); if(!timerval) return 0; if (timerval < 40*clockMhz) bits[byte] |= (1 << bitcount); if (bitcount == 0) { bitcount = 7; byte++; }else{ bitcount--; } } // checksum /* Little Endian */ bitints[0] = ((unsigned int) bits[0] & (0x000000FF)); bitints[1] = ((unsigned int) bits[1] & (0x000000FF)); bitints[2] = ((unsigned int) bits[2] & (0x000000FF)); bitints[3] = ((unsigned int) bits[3] & (0x000000FF)); bitints[4] = ((unsigned int) bits[4] & (0x000000FF)); if(((bitints[0] + bitints[1] + bitints[2] + bitints[3]) & (0x000000FF)) == bitints[4]){ temp = bitints[2]; humidity = bitints[0]; return 1; }else{ return 0; } } int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Configure the system clock to 40MHz if(ReadDHT() == 0) { //Failed result } else { // Stored in temp and humidity } }
  2. Like
    arre got a reaction from dubnet in DHT11 temperature & humidity sensor code snippet   
    Hi, 
     
    Thought I'd share a small code snippit I built to interface succesfully with the DHT11 temp & humidity sensor (4 bucks on ebay):
    #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/pin_map.h" #include "driverlib/gpio.h" #include "driverlib/systick.h" #include "driverlib/timer.h" int temp; int humidity; inline long WaitUntilPinState(int clockMhz, long pinbase, long pin, long timerbase, long timer, int previousstate, int usec) { // Debounce really not needed unless you have huge noise, but just in case (the processor is fast enough) #define DEBOUNCEMATCHES 5 long timermax; long timerval; int matches = 0; TimerDisable(timerbase, timer); TimerConfigure(timerbase, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT); TimerLoadSet(timerbase, timer, usec*clockMhz); timermax = TimerValueGet(timerbase, timer); timerval = timermax; TimerEnable(timerbase, timer); while(matches < DEBOUNCEMATCHES){ /* Wait for DHT to pull down */ if( GPIOPinRead(pinbase, pin) > 0 != previousstate > 0) { matches++; } else { matches = 0; } timerval = TimerValueGet(timerbase, timer); if(!timerval) timerval = 1; /* make sure we never return 0 by mistake */ if (timerval==timermax){ return 0; } } return timerval; } int ReadDHT() { // bit buffers & timeout char bitcount; char byte; char bits[5] = {0,0,0,0,0}; unsigned int bitints[6]; long timerval; int clockMhz; #define MY_PIN_PERIPH SYSCTL_PERIPH_GPIOE #define MY_PIN_PORTBASE GPIO_PORTE_BASE #define MY_PINNR GPIO_PIN_1 #define MY_TIMER_PERIPH SYSCTL_PERIPH_TIMER0 #define MY_TIMERBASE TIMER0_BASE #define MY_TIMER TIMER_B clockMhz = SysCtlClockGet() / 1000000; /* Configure hardware counter to check how long we are looping */ SysCtlPeripheralEnable(MY_TIMER_PERIPH); TimerConfigure(MY_TIMERBASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT); // request reading SysCtlPeripheralEnable(MY_PIN_PERIPH); GPIOPinTypeGPIOOutput(MY_PIN_PORTBASE, MY_PINNR); GPIOPinWrite(MY_PIN_PORTBASE, MY_PINNR, 0x0); // #loops = loops_per_us*time_in_us = time in us * loops/us = time_in_us *(clockfreq/10000000) SysCtlDelay(30000*clockMhz); // -> 30 ms /////// SET PIN HIGH (putting it to input will do) GPIOPinTypeGPIOInput(MY_PIN_PORTBASE, MY_PINNR); SysCtlDelay(10*clockMhz); /* Wait for DHT pull down */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,50)) return 0; /* Wait for dummy up */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,0,90)) return 0; /* Wait for dummy down */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,90)) return 0; // start receiving 40 bits char i; bitcount = 7; byte = 0; for (i=0; i < 40; i++) { /* Wait for pull up */ if(!WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,0,60)) return 0; /* Wait for pull down and count */ timerval = WaitUntilPinState(clockMhz,MY_PIN_PORTBASE,MY_PINNR,MY_TIMERBASE,MY_TIMER,1,90); if(!timerval) return 0; if (timerval < 40*clockMhz) bits[byte] |= (1 << bitcount); if (bitcount == 0) { bitcount = 7; byte++; }else{ bitcount--; } } // checksum /* Little Endian */ bitints[0] = ((unsigned int) bits[0] & (0x000000FF)); bitints[1] = ((unsigned int) bits[1] & (0x000000FF)); bitints[2] = ((unsigned int) bits[2] & (0x000000FF)); bitints[3] = ((unsigned int) bits[3] & (0x000000FF)); bitints[4] = ((unsigned int) bits[4] & (0x000000FF)); if(((bitints[0] + bitints[1] + bitints[2] + bitints[3]) & (0x000000FF)) == bitints[4]){ temp = bitints[2]; humidity = bitints[0]; return 1; }else{ return 0; } } int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Configure the system clock to 40MHz if(ReadDHT() == 0) { //Failed result } else { // Stored in temp and humidity } }
  3. Like
    arre got a reaction from bluehash in Electric Scooter LCD on dashboard, powered by a TI Stellaris Launchpad   
    Thanks guys.
     
    @@bluehash, the scooter uses a pack of 4 12V lead gel batteries (sort of lead-acid batteries, but without a liquid electrolyte).
    It's a "Qwic Emoto 87" and it looks like this: 
     

     
    @PTB: Yeah, the last picture on the forum here only shows the LCD on the dashboard without any protection. I later used a gluegun tofurther waterproof the LCD on the sides, and then put some black tape over the LCD sides to make it blend in more with the dashboard. (But I still have to test the waterproofing to be honest:)
    I actually don't have pictures of the finished LCD yet (?), but you can check out a low-res movie on the blog above:)
     
    Arnout
  4. Like
    arre got a reaction from PTB in Electric Scooter LCD on dashboard, powered by a TI Stellaris Launchpad   
    Hi all,
     
    Another project to the list: 
     
    I fitted my electric scooter with an LCD on my dashboard, to display power consumption and the voltages of the batteries, using the stellaris launchpad.
    The launchpad provided the digital out pins for the LCD (thanks to The_YonGrand for the lib), and the ADC measurements for the voltages & current of the battery.
     
    You can it out in detail on my blog: http://arre234.blogspot.be/ , or directly take a peak in the code on https://github.com/arre525/escooterlcd
     
    But here are already a few pictures to get you interested:)
     
     
     
     

     
     

     
     

     
    Arnout
  5. Like
    arre got a reaction from bluehash in Electric Scooter LCD on dashboard, powered by a TI Stellaris Launchpad   
    Hi all,
     
    Another project to the list: 
     
    I fitted my electric scooter with an LCD on my dashboard, to display power consumption and the voltages of the batteries, using the stellaris launchpad.
    The launchpad provided the digital out pins for the LCD (thanks to The_YonGrand for the lib), and the ADC measurements for the voltages & current of the battery.
     
    You can it out in detail on my blog: http://arre234.blogspot.be/ , or directly take a peak in the code on https://github.com/arre525/escooterlcd
     
    But here are already a few pictures to get you interested:)
     
     
     
     

     
     

     
     

     
    Arnout
  6. Like
    arre got a reaction from spirilis in Electric Scooter LCD on dashboard, powered by a TI Stellaris Launchpad   
    Hi all,
     
    Another project to the list: 
     
    I fitted my electric scooter with an LCD on my dashboard, to display power consumption and the voltages of the batteries, using the stellaris launchpad.
    The launchpad provided the digital out pins for the LCD (thanks to The_YonGrand for the lib), and the ADC measurements for the voltages & current of the battery.
     
    You can it out in detail on my blog: http://arre234.blogspot.be/ , or directly take a peak in the code on https://github.com/arre525/escooterlcd
     
    But here are already a few pictures to get you interested:)
     
     
     
     

     
     

     
     

     
    Arnout
  7. Like
    arre got a reaction from Automate in Electric Scooter LCD on dashboard, powered by a TI Stellaris Launchpad   
    Hi all,
     
    Another project to the list: 
     
    I fitted my electric scooter with an LCD on my dashboard, to display power consumption and the voltages of the batteries, using the stellaris launchpad.
    The launchpad provided the digital out pins for the LCD (thanks to The_YonGrand for the lib), and the ADC measurements for the voltages & current of the battery.
     
    You can it out in detail on my blog: http://arre234.blogspot.be/ , or directly take a peak in the code on https://github.com/arre525/escooterlcd
     
    But here are already a few pictures to get you interested:)
     
     
     
     

     
     

     
     

     
    Arnout
×
×
  • Create New...