Skip to main content

Posts

Showing posts from August, 2013

DS1621 with Raspberry Pi/ArchLinuxARM

Here is  how to get DS1621 I2C Temperature sensor working with Raspberry Pi running ArchLinuxARM

Make sure you have a working setup of RPi and Arch Linux, if not refer here:
HelloWorld in Lua on Raspberry Pi running Mihini on ArchLinux with Koneki as IDE

After you have the setup ready, attach the DS1621 sensor to your RPi as shown in the schematic below.
I have Model B Revision 1.0 Raspberry Pi (cat /proc/cpuinfo shows Revision : 0002)


The following commands issues to RPi over a terminal (SSH or Serial using PuTTY):

Install i2c-tools:
pacman -Sy i2c-toolsInstall lm-sensors:
pacman -Sy lm_sensorsOpen kernel module load config file for editing:
nano /etc/modules-load.d/raspberrypi.confAdd the following line at the end of the file and save it.
i2c-dev

This will load the i2c-dev kernel module at boot up.
This module will allow you to access the I2C bus via /dev/i2c-0Reboot Raspberry PiWhen the Raspberry Pi comes back on, issue the following command:
i2cdetect -y 0

You will see the following output…

Reading switches via GPIOs on Raspberry Pi in Lua (ArchLinux+Mihini)

My previous posts on using Eclipse M2M with Raspberry Pi:
HelloWorld in Lua on Raspberry Pi running Mihini on ArchLinux with Koneki as IDE (link)LED Blinky in Lua on Raspberry Pi running Mihini on ArchLinux (link)Autostart Lua script on RasPi+Archlinux+Mihini at power up (link) After having accomplished the above, I moved on to reading switches and controlling LEDs My schematic looks like below:
I wanted to toggle an LED for each press of the corresponding switch. I paired up each switch to an LED:
Switch at GPIO 4 would control the LED at GPIO 22 Switch at GPIO 17 would control the LED at GPIO 23 Switch at GPIO 18 would control the LED at GPIO 24 Switch at GPIO 21 would control the LED at GPIO 25
I registered a hook function which would be called whenever the state changed of any of the four GPIOs to which the switches were connected. From within the hook functions, LED corresponding to that switch is toggled. A message is printed from inside the hook function with timestamp retrieve…

Autostart Lua script on RasPi+Archlinux+Mihini at power up

After having setup Mihini on my Raspberry Pi/ArchLinux and having blinked a few LEDs via GPIOs, I wanted to try out configuring Mihini to start a Lua script at power up.

Benjamin CabĂ© (blog | twitter) and the mihini contributors (twitter) pointed me in the right direction: Creating Launcher & Installing App | Appmon Daemon

First up, here is a code to blink four LEDs. How is it better than the previous code that blinked four LEDs together? Well, this one used the sched module to blink the four different LEDs at different rates using 4 tasks in parallel. 4 instances of tasks are created from the same function blink() using the sched.run. For each instance, we pass different parameters to blink a different LED at a different rate. We use sched.wait() within a task to relinquish control to another task waiting in queue - this is how collaborative multitasking is implemented here using the sched module.

blinky.lua:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 …

LED Blinky in Lua on Raspberry Pi running Mihini on ArchLinux

After setting up Eclipse M2M toolchain for Raspberry Pi, I wanted to try out a simple lua script to blink LEDs using GPIOs. Here is the schematic and lua script for the same. I used the 3.3V available on RPi for powering the LEDs. 1 kiloohm resistors were used to limit the current passing through the LED. The cathodes of the LED were connected to drain the current into the GPIO pins. I used 4 LEDs connected to 4 different GPIOS (GPIO 22, GPIO 23, GPIO 24, GPIO 25).




1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41package.path='/opt/mihini/lua/?.lua;/opt/mihini/lua/?/init.lua;'..package.pathpackage.cpath='/opt/mihini/lua/?.so;'..package.cpathlocalgpio=require"gpio"localclock=os.clocklocalfunctionsleep(n)-- secondslocalt0=clock()whileclock()-t0<=ndoendendlocalfunctiontoggle_pin(n)localstat=gpio.read(n)ifstat==1thengpio.write(n,0)elseifstat==0thengpio.write(n,1)endendlocalfunctionmain()g…