Reading sensor data from a DHT11

Reading data from an DHT11 using an arduino is fairly simple. Library used: https://github.com/adafruit/DHT-sensor-library

Preliminaries

  • using arduino-mk

  • Arduino Linux 64bit package Version 1.0.5

  • (more see previous blogposts in arduino category)

Steps

  • Clone library in libs folder

  • Create Makefile

BOARD_TAG    = uno
ARDUINO_LIBS = DHT-sensor-library
USER_LIB_PATH = ../libs/

include /usr/share/arduino/Arduino.mk
  • try example code:

https://github.com/adafruit/DHT-sensor-library/blob/master/examples/DHTtester/DHTtester.pde

My DHT11 has a different pin layout: - + S. The rest of the example code works without modifications.

Arduino restart

My Arduino is working without problems for a few years now. But now it's time to try a few new ideas and plant a few new ones.

The Makefile from my 2011-Blogpost doesn't work with the newest Arduino-Package. But there is a better one: https://github.com/sudar/Arduino-Makefile And the best is that Debian/Ubuntu has a package for it arduino-mk.

void setup() {
  // initialize the digital pin as an output.
  // Pin 9 has an LED connected on most Arduino boards:
  pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(9, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Code to get the Arduino Uno blink

BOARD_TAG    = uno
ARDUINO_LIBS =

include /usr/share/arduino/Arduino.mk

I tried the same with a leonardo which seems a bit more error-prone. Resets needs to be pressed and a disconnect from usb before programming helps.

Redirects in Django urls including parameters

A change of url schemata forced me to redirect some urls in my Django app. I wanted to use reverse, RedirectView and url parameters.

The View:

from django.views.generic import RedirectView
from django.core.urlresolvers import reverse_lazy

class RedirectViewCustom(RedirectView):
  """view to redirect including all named parameters to a specific lazy url name"""

  def get_redirect_url(self, **kwargs):
    params = self.kwargs
    name = self.kwargs.get('redirectname')
    if name:
      del params['redirectname']
      return reverse_lazy(name, kwargs=params)
    else:
      raise ValueError, "redirectname not set in RedirectViewCustom call."

In urls.py:

url(r'^old-name/(?P<slug>[a-zA-Z]+)/(?P<param>[a-zA-Z0-9-\-]+)/$',
  RedirectViewCustom.as_view(),
  kwargs={'redirectname':'some-name'}),

Tested with Django 1.4.