Configuring a 5″ Raspberry Pi Display

I received a 5″ 800×480 Raspberry Pi screen recently, and needed to get the screen and touch input working correctly. After some digging around I got everything working, here’s how I did it.

The screen is marked as “5inch HDMI Display, 800×480 Pixel, XPT2048 Touch Controller”, and doesn’t need any drivers to get it working, despite coming with a driver CD.

Insert the SD card from your Pi into your computer, and open the config.txt file, we’ll be making a couple of changes here.

Resolution and touch input

The Pi can’t auto-detect the screen resolution, so we’ll need to let it know how many pixels we have. Add the following lines to set the resolution.

hdmi_group=2
hdmi_mode=1
hdmi_mode=87
hdmi_cvt=800 480 60 6 0 0 0

Now we need to tell the Pi that we have a touch screen connected, in the same file add the following lines

dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=ads7846,penirq=25,speed=10000,penirq_pull=2,xohms=150

Save the file, and put the SD card back into the Pi. You’ll find the whole screen being used and the touch screen working… but the touch screen input is off by a bit, which we’re going to fix next.

Calibration

We can install a calibrator by running this in the terminal

sudo apt-get install xinput-calibrator

Then you can run it by typing

xinput_calibrator

It’ll get you to touch on four calibration points, after which your touch screen should work much more accurately.

To make this change permanent you’ll need to copy the output from the above command into a config file. It’ll look something like this:

Section "InputClass"
        Identifier "calibration"
        MatchProduct "ADS7846 Touchscreen"
        Option "Calibration" "159 3903 139 4046"
        Option "SwapAxes" "0"
EndSection

Edit your config file with:

sudo nano /etc/X11/xorg.conf.d/99-calibration.conf

Paste the output into that file, save, and you’re done.

Permissions

For some reason the above changes will modify some permissions, which means you will get a non working login screen at boot. To fix this press Ctr-Alt-F5 at the login screen to get the command line.

Login there with your username and password (default is pi and raspberry) then run the following command to fix the permissions.

chown pi:pi .Xauthority

Reboot, your next login should work as normal

ESP8266 + temp sensor fail!

I’ve designed a few sensor boards that collect temperature, humidity, light, sound etc… and send them over wifi, or a local radio network. Recently I switched to the ESP8266, and had my first fail.

The temp sensor was mounted next to the ESP8266, which is fine until you turn everything on, and realise that the ESP gets warm and completely compromises the readings on the temp sensor.

Oops!

Version 1

I designed a second version of the board, with some physical separation between the ESP and the temp sensor, making cuts into the board to stop the heat traveling through to the sensor area.

Version 2

Even with this change we still get heat transfer between the ESP and the temp sensor. Within 10 minutes of power up we have a 4°C rise in temperature readings.

temp

At this point I have a few options

1. Re-design the board, giving even more physical separation between the ESP and the sensors
2. Add a heatsink to the ESP to try and dissipate the heat
3. Modify the software to put the ESP into sleep mode between sensor readings, to reduce heat output

I’ll try a combination of the second two, although ultimately a new board might be the better solution.

ESP8266 WifiClient Error

I’ve been writing some code for the ESP8266, using it to send sensor data to a server, to be logged and charted. I started with the WifiClient example, from the ESP8266 Arduino board manager.

I modified the example code to use multiple sensors, and came upon an issue. The board started resetting itself, leading me to think I had a hardware issue, especially since two boards were doing it.

I was receiving this error on the serial line

ets Jan  8 2013,rst cause:2, boot mode:(1,7)
ets Jan  8 2013,rst cause:4, boot mode:(1,7)
wdt reset

The watchdog seemed to be unhappy, and was resetting the processor.

I had commented out the following line, right after the data transfer had been started.

String line = client.readStringUntil('\r');
Serial.print(line);

String line = client.readStringUntil(‘\r’); empties the read buffer, and is crucial, even if you don’t do anything with the results.

Putting this line back in fixes all issues.

So if you’re having issues with that sketch, with random watchdog resets, make sure you are reading the return data to clear the buffer, and keep the watchdog happy.

Workshops

We’ve been running a series of workshops at Cambridge Hackspace over the last few months, getting people to build electronics projects.

The evening is spent learning basic soldering techniques, assembling and soldering the components, and then programming the Arduino software. Usually we learn a bit of fault finding too, as there’s always someone that applied too little or too much solder somewhere, and we have to track it down.

soldering

So far we’ve run workshops to build clocks and thermometers, we also have upcoming workshops building spectrum analysers, multimeters, wifi display screens, and internet connected environmental sensors.

clock

The inspiration came from Paint Nite, a local company providing group painting classes, where you go home with your own painting to hang on your wall. You get to learn, create, and have something to show for it afterwards.

That’s exactly what we’re doing at hackspace, with a focus on electronics and software.

Not only do our up-and-coming electronic engineers get to benefit from the evening, but we get to earn some money too, which goes towards improving our workshop and making the space more appealing to new members.

hackers

ESP8266 as Arduino

You can program the ESP8266-12E as an Arduino, using the board manager plugin in the Arduino IDE. It’s great for deploying simple code with access to wifi, and at less than $2 (including shipping) it’s really affordable.

Because it’s made by multiple sources in China, and because they don’t seem to talk to each other, you get some inconsistencies between the seemingly identical boards.

esp8266

Pins 4 and 5 are swapped on some of them, which means you have to account for this in your PCB designs. I2C runs on these pins, and so it’s important you have them the right way around.

The operation of the reset button is also different on different boards. Usually you need to press the reset button on power up to be able to program, but on some boards you need to keep that button pressed until the upload has started.

This makes the ESP8266 a potentially tricky board to use at first, if you don’t know the quirks.

Modify git commit timestamp

Sometimes it’s useful to modify the timestamp of a git commit, like when archiving old files (I usually want the timestamp to match when the file was last modified, rather than todays date)

This can be done easily once the files have been committed, but before they are pushed

git commit --amend --date "Apr 19 19:12:01 2010"
GIT_COMMITTER_DATE="Apr 19 19:12:01 2010" git commit --amend

You can now see the updated timestamps in your git history, and can push you’re file to Github with a more appropriate timestamp.

Rocketeer on Laravel 5

Using Rocketeer to deploy code with Laravel 4.2 is nice and easy, using the standard Rocketeer library in Laravel’s composer file. Rocketeer doesn’t play so well with Laravel 5, and so we have to approach the install from a different direction.

The solution here is to use composer to install Rocketeer globally.

composer global require anahkiasen/rocketeer

Config files can then be found in the .rocketeer folder, you can also setup your environment using the ignite command

rocketeer ignite

Then, to deploy your code you can use:

rocketeer deploy

Easy!

Update

If this method doesn’t work, you can download the file manually

wget http://rocketeer.autopergamene.eu/versions/rocketeer.phar
chmod +x rocketeer.phar
sudo mv rocketeer.phar /usr/local/bin/rocketeer

Full Server

Recently one of our app servers stopped serving, the server was running, but it had run out of disk space. The database wasn’t too large, and the Laravel apps log files weren’t massive.

The first stop then was to find any large files, to see what was clogging up the system.

find / -size +10M -ls

This revealed a 17Gb log file: /var/log/mysql/mysql-slow.log

It appeared that MySQL was taking it’s time with some queries.

We sync our database with various external APIs every day, these are inserted in bulk, so I don’t mind them taking over 0.1 second to run (the default slow-query log threshold set in our mysql config). What I do mind is having the server run out of space due to large log files.

Read More

Laravel to Digital Ocean using Server Pilot and Rocketeer

Recently I have been using Digital Ocean, they provide simple, quick, secure, and easy to setup servers which are perfect for hosting Laravel projects. They use SSD drives, take less than a minute to create, and cost as little as $5 a month, pretty nice!

I also recently discovered Server Pilot, a *really* easy way to manage your new server. With one line of code in terminal it sets up the server ready for use. It installs ngnix + Apache (yes, both at the same time), deals with security, then makes virtual hosts, ssl certificates and mysql (including security) as easy as 1 click.

Rocketeer is a deploy script, used for deploying php code simply, it integrates with Laravel nicely too.

Laravel is my MVC framework of choice, and here’s how I get it running on Digital Ocean using Server Pilot and Rocketeer.

logos

In this post we’ll be

  1. Creating a Laravel project on your local machine
  2. Uploading that to Github or Bitbucket (I’ll be using Bitbucket)
  3. Creating a server on Digital Ocean
  4. Using Server Pilot to setup the server for our needs
  5. Logging into the server to confirm a few basics
  6. Using Rocketeer to deploy our code to the server

This guide assumes you can use git, and you have accounts with the following sites:

It also assumes you have Git, Composer, and PHP installed locally.

Right, lets get stuck in!

Read More

PiTFT – Load the desktop with a physical button (startx)

I recently discovered the PiTFT screen, a 2.5″ TFT screen from Adafruit that sits on top of a Raspberry Pi. You can send it images, video, or set it up as a desktop environment. This became immediately appealing as I realised I could setup the pi as a webserver for my home automation, and load the browser fullscreen to interact with it. Oh yeah, it has a touchscreen, making interacting with the interface really nice.

pitft2

One small issue it getting the screen to start a desktop. You have 2 options:

  1. Start the pi, connect to ssh and type startx
  2. Start the pi and make the default desktop the tft (meaning no output anymore on hdmi)

Neither of these are great, one involves having to login every boot, the other means you don’t get your regular desktop over hdmi.

Enter option 3!

Read More