Category: Raspberry Pi (Page 2 of 3)

Playing with single-board computers

raspberry pi

Over the last few years, I’ve been tinkering with small gadgets. It all started when I got one of the original Raspberry Pi Model B devices. Since then, I’ve learned a lot about Linux, and what you can do with these tiny computers. Recently, I’ve been experimenting with additional single-board computers- namely the Raspberry Pi B+ Model, the Arduino Uno and the Intel Galileo (1st generation).

Compared to the original, the Raspberry Pi B+ Model has 4 USB ports rather than 2, an extended GPIO header and a micro SD slot. I received the new Pi days after it was released and I was impressed. The layout of various ports have also been rejigged to allow power cables etc to sit in a “better” position. Additionally, I purchased a Pibow Coupe case from Pimoroni which allows for easy access to the GPIO header. This permitted me to place an LCD screen on top of Pi and build a Lego frame around it to make it sit upright. I then wrote a small program that scrolls my Twitter feed across the screen (I’m still making improvements to my Python script).

The Arduino Uno was purchased a while ago but I didn’t really do anything with it. I have been learning more about microcontrollers in my spare time and decided to see what I could make. Thus far, I’ve made an LED on the board blink (…amazing, huh?), connected an old Nokia 5510 display to it to scroll data and connected retro bubble LEDs, originally used in the Hewlett-Packard 3x-series of calculators. The bubble LEDs are rather cute and I want to use these in a larger project. There’s various components sitting on my desk at the moment such as small DC motors, propellers and sensors so I’m hoping to make something neat. Still have lots to learn!

That brings me to the Intel Galileo (1st generation). I applied for a free one a while ago when Intel were giving them away. Unfortunately, they were in high demand and I missed out, however, I managed to borrow one from work. As with the Arduino, my first task was to get the blink program running on the board (let’s face it, it’s “Hello World” for microcontrollers). Getting it to work with the Nokia screen was difficult and I couldn’t get it to work with my AdaFruit LCD Display- additional libraries may be required…it wasn’t clear. I managed to get the bubble LEDs to work with it however, the board was very slow. I tried to display the word “code” and the letters flickered considerably (see my YouTube video- https://www.youtube.com/watch?v=fWpmZ09_h0w). It’s possible to install the “Bigger” Linux image on the Galileo via a micro SD card. I managed this and was able to SSH into the board. At this stage, I haven’t tried anything else with the device as I’m finding it a bit slow. As I mentioned before, I’ve got lots of components to play with, so I *might* be able to get something more impressive working with it!

More updates when I’ve built something else.

Joining GitHub

At the beginning of the year, I joined GitHub. I figured it might be useful for scripts etc I write when fiddling around with the Raspberry Pi. This month I actually created a repo (don’t worry, it’s nothing exciting- it’s just a script to stop the Raspberry Pi wifi disconnecting).

You can find me at https://github.com/Lynsay

Keeping the Raspberry Pi Connected via Wi-fi

A few months ago, I set-up my Raspberry Pi with a wi-fi adapter. More recently, I’ve noticed that the wi-fi connection occasionally drops out, and the adapter never attempts to reconnect to the network. This is a problem if I’m trying to access the Pi via SSH.

At this stage, I’m still unsure as to why the wi-fi drops out. Initially, I thought there was an issue with my interfaces file however, adding “auto wlan0” to it in an attempt to force a reconnect failed. Trawling through the syslog files revealed that when the wi-fi dropped, a “link beat lost” message was recorded. I was fairly certain it wasn’t a power supply issue messing with the USB ports so my next idea was to create a cron job to check the status of the wi-fi adapter. This solution worked and I have outlined the steps I used below.

First of all, you need to create a new bash script in the following location (note, I’m using nano as my text editor):

cd ~
sudo nano ../../usr/local/bin/wifiscript.sh

The file has the following permission (the user can execute the file)

sudo chmod 0100 ../../usr/local/bin/wifiscript.sh

Next up, here’s the script I used to check the status of the wi-fi connection. What does it do? The Pi attempts to ping Google. If the Pi cannot successfully ping Google, then the script ensures the wi-fi interface is down before bringing it back up. Else, the wi-fi is connected and no action needs to be taken (yay!).

#!/bin/bash
 
TESTIP=8.8.8.8
 
ping -c4 ${TESTIP} > /dev/null
 
if [ $? != 0 ]
then
    logger -t $0 "WiFi has gone down- run ifup"
    ifdown --force wlan0
    ifup wlan0
else
        logger -t $0 "WiFi is currently ok"
fi

Now we need to create a new cron job to schedule when the wifi script runs. The new cron job goes here:

cd ~
nano ../../etc/crontab

How to add the new cron job to crontab:

*/5 * * * * root    /usr/local/bin/wifiscript.sh >> /var/log/syslog 2>&1

The above line writes all the messages generated by the wifiscript.sh file to the syslog file (so “WiFi has gone down- run ifup” or “WiFi is currently ok”). The cron job is also scheduled to run every 5 minutes.

…and that should be it! Well, not quite. It’s probably a good idea to test if the script actually works.

Take the wi-fi interface down:

ifdown wlan0

Of course, this will break your SSH connection. Wait 5 minutes and the wi-fi interface should come back up, allowing you to SSH back into the Pi.

One last check. Have a look at the syslog file. You should see where the wi-fi disconnected and where it reconnected.

nano ../../var/log/syslog

Now you’re done!

Note: this is my first attempt at writing a bash script and a cron job so comments and criticism is welcome!  In the process of writing this blog post, I found Arne’s Blog to be particularly helpful.

« Older posts Newer posts »

© L.Shepherd 2006-2021. All rights reserved.

Modified version of Hemingway Theme by Anders Noren