Jump to content


  • Content count

  • Joined

  • Last visited

  • Days Won

  1. 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. @spirilis: It's limited to 50 km/h (+- 30 mph I guess). The batteries are unfortunately the achilles heel of electric vehicles. They're expensive, and have relatively low energy/weight ratio. In my case, a 600 euro battery pack gets me 40 km until you really need to recharge, for 2 years until the pack wears out. But since I live quite close to work, it's still a lot cheaper than a car, faster than a bike, and not as loud/smelly as a petrol scooter:) More importantly, it's electric! Which means I can measure the power it produces!
  3. arre

    Using Stellaris Launchpad as a Thermometer

    Thanks nemetila, for your code! I hooked it up to a raspberry pi, and it has been measuring the temperature of my room more or less for two months now. This is what it looks like now: Summer's almost over here!
  4. 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
  5. 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. arre

    Very Basic HD44780 driver for Stellaris LaunchPad

    Awesome! Gonna try this shortly!