Categories
Electronics PiDashCam Raspberry Pi

PiDashCam – Issues

Well. That didn’t go to plan. I managed to hook the PiDashCam up to the car. It powered on fine, and has recorded, however I forgot to change the settings and it recorded in 10 second blocks. I also mounted it incorrectly, so it sort of sat at an angle. I also went out when it was a bit dark so the images are really not great. The worst part, however, is that the Raspberry Pi Zero didn’t seem to grab the time from the RTC Module. I’ll need to do some digging and figure out exactly where its all went wrong…

Very cropped side by side

The camera, although a lower resolution, appears to capture more of the image. Its a shame it appears very hard to see properly, but I’m hoping thats to do with the camera_mode, or possibly the sensor. More tinkering required!

I’ve also been thinking about having a simple way to change the camera_mode when recording. I think I’m going too implement a 3 LED system, using Binary counting, so show which camera_mode I’m using. I’ve have a (very) quick look at Alex Eames code for button presses here and think I can change this so that a quick press is camera_mode, a longer press is stop recording (useful for when I have it hooked up in the house to view files instead of running pkill every time I log in), and a long press is shutdown. Ultimately the first press can be used as a “protect” marker on files should it be required, but I’m getting ahead of myself!

# The following Python code has been copied from https://github.com/raspitv/bikedashcam/blob/master/dashcamcorder.py - Alex Eames and Raspi.tv


try:
    while True:
          # this will run until button on GPIO13 is pressed, then
          #   if pressed short,     stop recording
          #   if pressed long,      close program
          #   if pressed very long, shutdown Pi gracefully
        print "Waiting for button press"
        GPIO.wait_for_edge(13, GPIO.FALLING)
        print "Stop button pressed"
        stop_recording()

          # poll GPIO 13 bottom button at 20 Hz for 3 seconds
          # if still pressed at the end of that time period, shut down
          # if released at all, break
        for i in range(60):
            if GPIO.input(13):
                break
            sleep(0.05)

        if 25 <= i < 58:              # if released between 1.25 & 3s close prog
            print "Closing program"
            GPIO.cleanup()
            sys.exit()

        if not GPIO.input(13):
            if i >= 59:
                shutdown()
Categories
Electronics GitHub PiDashCam Raspberry Pi

An Update…

So, after being alerted by the Raspberry Pi Weekly mailing list to a liveblog by Alex Eames detailing his process for building a biking “dash cam” I thought I better start detailing what I’ve done, what I’m currently doing, and what I plan to do with my PiDashCam project which has taken a back seat for a number of months years. I’ve watched the videos Alex has made, but not yet looked at the code. My first post was using an Original Raspberry Pi with no camera attached, hooked up to a GPS module to ensure I got valid GPS data, and a small SPI screen so I could view the data

The Before

Unfortunately work and life took over and apart from spending a few odd minutes here and there over a number of months, no real advances were made apart from this update in which I was now testing with the Raspberry Pi Zero W, and figuring out how to get it talking to the GPS module, with the accelerometer, button and RGB LED all hooked up (but still no camera).

The After

I’m now going to try and update here with that I’ve decided upon, some new design goals and design directions, and the code needed to run my PiDashCam, in addition to stripping back to the bare essentials (you know, like being a camera).

I’ve remained with the Raspberry Pi Zero Wireless and I have an RTC Module hooked up, in addition to the camera, and one button. At present, the Pi boots, and automatically runs two scripts.

The new, updated, lesser qualified PiDashCam

The first, record.py, grabs the date and time, starts the camera, and starts recording, updating the annotated text on the screen. It then outputs a new file named after the current year, month, day, hour, minute and second (YYMMDDHHMMSS) every pre-determined number of seconds (roughly). You will be able to view this source code on GitHub as soon as I get round to uploading it. It also annotates the current date and time, and the current camera_mode.

The second, start.py, simply waits for the button press. At present it only detects an on push, nothing fancy like a multiple second hold. It then gracefully pkills the Python Process that is controlling the camera and after a few seconds delay, initiates a shut down of the Pi.

As its a bit unwieldily at present, I’ve stuck and blu-tacked it to a cheap dash camera I bought from eBay or AliExpress at some point or another. 

The camera works when testing in my house. I’ve still to take it a road test and make sure it works. I have a second, cheap Dash Cam that was another eBay or AliExpress special that does what it needs to do, but the quality is pretty poor. I plan on keeping both cameras connected and comparing the output. If I cant at least match the quality of a sub £20 Dash Cam then there’s no real point in continuing this one.

My Plan is as follows

  1. Test the camera, make sure it works in the car
  2. QUALITY CHECK
  3. Test multiple camera modes with the First Edition Raspberry Pi Camera
  4. Test multiple camera modes with the Second Edition Raspberry Pi Camera
  5. Test multiple camera modes with a cheap FishEye Pi Camera
  6. QUALITY CHECK
  7. Add in GPS Logging
  8. Add second button for marking of emergency record
  9. Add in G-Sensor for additional annotation and Emergency Record Function
  10. QUALITY CHECK
  11. Create a settings style file where all user-selectable settings are set
  12. Put it all in a nice case
  13. Work out a way to convert the raw h264 files to a usable mp4 format
  14. Build a nice web-based interface with an API so that apps can access the files/settings via Wi-fi
  15. Integrate with the CAN-Bus to take car data for better analysis of driving etc.

After each quality check, if the quality is not something that is useful then it could be a cancellation of the project. I’m trying to provide a more organised, and focused attempt this time and having these Design Goals will ensure that I focus on what’s required without jumping ahead. As always, I’m a great started and terrible finisher, but hopefully that will change!

In addition to the PiDashCam, I’m Aldo going to try my had again at small electronics. I’ve had a plate of 100 of these WS8211B RGB LED’s, and due to the way I stored them, they managed to snap. Playing about with the layout meant I could resonable build a Binary Clock, which I’ve wanted to do for quite a while. Given how many I had though, I figured I could extend this out and make it alternate between a Binary and Regular clock, and seeing as I have an ESP8266 spare, this could all be controlled wirelessly, with the time updated from an NTP server. But, there will be a separate blog post about that!


Updated 20/02/2019 with correct links to Alex Eames blog and minor technical details.

Categories
Electronics GitHub PiDashCam Raspberry Pi

Pi Zero W – PiDashCam Part 2

There will be a longer post about the newly released Pi Zero W, however suffice to say as soon as I saw it was available it was ordered, and I now have one!

There has been a few changes to the PiDashCam project, which has included moving to the Pi Zero when v1.3 was released (As it had a camera connector on the board). I missed my opportunity to write about those updates!

The Pi Zero W uses a similar set up to the Pi 3, in that the built-in bluetooth capabilities use the hardware UART, which means that my UART GPS receiver wont work.

As it is so similar to the Pi 3 (excluding the memory and processor) the current Device Tree for disabling bluetooth on the Pi 3 works for the Pi Zero W.

I’ve included some code below. This starts from a fresh install and allows you to use the hardware UART of the Pi Zero W and disables bluetooth on that board.

I hope it helps someone! (Also, feel free to replace vi with nano – I’m trying to teach myself Vim).

sudo vi /boot/cmdline.txt

in this file, remove the following text:

console=serial0,115200

Save and close the file. Next up,

sudo vi /boot/config.txt

and add the following to the end of the file:

enable_uart=1
dtoverlay=pi3-disable-bt

Next, it’s these three quick commands which includes a reboot of the Pi Zero W, which enables hardware UART:

sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service
sudo reboot

To complete the GPS side of things however, continue with the following:

sudo apt-get install gpsd gpsd-clients python-gps
sudo systemctl stop gpsd.socket
sudo systemctl disable gpsd.socket

and finally,

sudo killall gpsd
sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
cgps

which should see you getting data from the GPS Receiver.

Thanks to Adafruit for their existing tutorial, and the Raspberry Pi github/forums and IRC for the Device Tree information.

Categories
Electronics Raspberry Pi

The Raspberry Pi Dash Cam Project – Post 1

I’ve been toying with the idea of building a dash cam using a Raspberry Pi for a while. Every now and then I’ll buy something I think I’ll need for the project, hoping that I would get some time to work on it.

I’ve had a few days holiday, and one of my aims was to at least build a prototype in the days I had off.

I haven’t built a prototype, but I have the majority of parts together and verified that they worked! And it was surprisingly easy, apart from a 1.8″ Display (more on that later!).

Firstly, why not just buy one? Because I think I can build this, and I think I can enhance it and add to it, especially if I splash out and buy a Raspberry Pi 2! Also, why not?

My plan is to have the Raspberry Pi Camera Module recording as soon as the Pi boots to an acceptable state. A GPS receiver should then log the current GPS Position, heading and speed to a text file, and hopefully output some of that to a display. Likewise, an accelerometer and gyroscope should hopefully offer some additional readings to show the standard of driving.I plan to power the Pi via the cars 12v source (the accessory port or cigarette lighter). I will also have to create a safe power circuit so that once the vehicle has been switched off, the Pi shutdown gracefully. I will also have to make sure that when the vehicle starts there won’t be any sharp spikes in electricity which could fry the Pi.

So far I have:
The Raspberry Pi (Model B – Model B Rev 2 if required)
Raspberry Pi Camera Module
A DS3231 RTC (i2c)
A GPS Receiver (UART)
1.8″ Display (SPI).

I have backed a BerryIMU, which has an accelerometer, gyroscope and magnetometer, which will connect over i2c, but that has still to be delivered.

To mount the camera to the window, I purchased some suction pads (the ones with nuts) and I’ll create a custom camera mount to use them with.

Yesterday and today I spent some time with the equipment I have to make sure it all works together, which, excluding the camera, it does! I’ve excluded the camera during this round of testing I want to get everything else working first. Heres the equipment, breadboard style. Please excuse the dust! The Pi was stuck behind my TV.

Heres a quick video of the Pi being powered up in my car, using the equipment I already had to hand. Sorry about the black box, but this GPS Receiver is pretty accurate!

Just now I’m running stock Raspbian, but I have also been playing with buildroot, specifically gamaral’s pre-built image.

It really does boot that quick. Once I have everything set up in Raspbian, i’m hoping a few more days of compiling will get me a full featured Dash Cam that boots that quickly using buildroot. I’m hoping that the recording will start within 5 seconds of power being applied.

All my goals for the system as pretty much listed above. I just have to start learning Python! Good think I backed another Kickstarter project!

With regards to the 1.8″ Display, that was a bit harder to set up.

I was under the impression the Display I had used a ST7735 driver, as everywhere online said thats what the display used. It doesn’t. It actually uses a HX8353 driver.

There is some commands below. Each command is on a separate line and should be executed separately.

I had to install a custom version of the Raspberry Pi’s firmware, developed by notro using this command:

sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update

and then

sudo reboot

This custom firmware contains all the drivers needed to use the screen on the Pi. I could compile the software myself, but this is a proof-of-concept to make sure everything works. I then shut down the Pi, and hooked up the display as per this wiring diagram (please excuse the rubbish 5 minute job):

hx8353d

One thing to note is that I hooked the Backlight directly to 5v, so the backlight is always on when power is applied to the screen.

I then fired the Pi up, and typed the following commands:

sudo modprobe fbtft dma
sudo modprobe fbtft_device custom name=fb_hx8353d  gpios=reset:25,dc:24 speed=16000000 rotate=270 bgr=1
con2fbmap 1 1

This gave me the console on the screen. I then modified /etc/modules  (using sudo nano /etc/modules), and inserted the following lines at the end

fbtft dma
fbtft_device custom name=fb_hx8353d  gpios=reset:25,dc:24 speed=16000000 rotate=270 bgr=1

It’s as easy as that!

Now, to learn Python!

Categories
Electronics PHP

Just a little bit more.

That’s what I’ve been like over the last few days. Every time I try to move away from my computer I think of something I can change, or a small bug that I can fix over at whatplanshouldiget.uk.

I mentioned that site in my last post. It was going to be a quick script. A quick play around with PHP to keep me fresh, however still help me decide what price plan to get the new iPhone on, and possibly help others. I think, today, barring any bugs being found, it’s finished – excluding extra price plans being entered from MNVO’s.

A total of 1259 lines of my own code spread over 5 files. That’s not a lot in the grand scheme of things. That’s not a lot point-blank. But for something that started out as a simple exercise  turned into a little bit more. I’m proud of it. My next task, being as its possibly only valid for a few months until the UK Carriers start offering cut price plans, is to turn it from procedural code into object orientated code.

I’ve been using PHP since Version 4. Version 4 was really easy to get into. It wasn’t strict with coding styles (as long as you followed the syntax), and has garnered a reputation as helping to create the worst developers in the world. PHP 4 was almost exclusively procedural, as well as a whole host of other things I won’t even pretend to understand. PHP 5 came along and changed all that, and I didn’t really keep up with the times. I’m aware of some of the syntax, and the reasons, but I still don’t fully grasp the idea of OOP. This small site will be a great stepping stone!

Categories
Electronics General PHP

A new iPhone?

Well. It’s sort of guaranteed that I’ll be buying the new iPhone when its launched. The announcement is in 4 days, and the Keynote will be streamed live. I hope it’s streamed via the Apple TV again.

Countdown to Apple Event
Countdown to Apple Event

I’m not going to post about the handset or the specifications. That has been done again and again.

My biggest issue when it’s time for me to upgrade my handset is trying to figure out the best plan, and whether its worth purchasing the handset outright and taking a SIM only deal, or taking out an actual contract.

In the UK, we have a number of options for phones. The first (and most common) option is to take out a (now standard) 24 month contract. You pay more per month, but in that monthly payment you pay for the handset and for the service. Taking an iPhone 5S for example, I can grab a 16Gb iPhone 5S on the o2 network with Unlimited Minutes and Texts with 2Gb of 4G data for £43 per month, with no charge for the handset. Thats it. You walk in, get a phone, no payment, and walk out. Alternatively, I can pay £49.99 for the handset with the above options, and pay £38 per month. So, two options already and thats for the same contract. Doing the math and basing it on the average monthly cost, ( (£38 x 24) + £49.99 = £40.08 vs £42) shows the better deal to be £40.08.

Then we have SIM only deals. This is where you purchase the device out right (usually at Apple prices, then its “Factory Unlocked” – gives a greater re-sale value) and then pay monthly just for the plan. Again, you get different deals if you take out a “rolling” 30 day contract, or a 12 month contract. Again, using o2 as an example, the same plan as above would cost £22 per month for a 30 day rolling contract, vs £20 per month for a 12 month contract. Again, doing the math and basing it on the average monthly cost over 2 years, factoring in the price of an iPhone 5S 16Gb ( (£20 x 24) + £549.00 = £42.87) shows the better deal to be £40.08, i.e paying £49.99 for the handset and paying £38 per month. I’ve only included the £20 per month tariff as I’m basing this on a 24 month contract.

So, I have maths. Thats only comparing 1 plan with 3 options. To do this with every tariff available in the UK with the various handsets would take a fair bit of time. To that end, I created a website. WhatPlanShouldIGet.uk. Its pretty simple. Right now, it only allows you to enter a purchase price for a handset. As soon as the new mobile tariffs are announced for the iPhone 6 (or whatever it will be called), I will update the site with the various bits of data required. You will then be able to choose the handset, and the site will give you a nice, already worked-out table for your comparing pleasure!

The above assumes a lot of things. It assumes you have the cash available to purchase an iPhone outright. It does not take into account any interest rates imposed by credit card companies if you purchase the handset on a credit card (although that is a pretty good idea – new feature request!) and it does not take into account any loyalty or other discounts you may be offered.

It’s just a simple, quick and easy tool to work out What Plan Should I Get.

The site itself is written in PHP. It uses MySQL for backend storage, and bootstrap to make it look nice. I’ll post the code at some point, but as its a public facing site, I want to make sure I haven’t left any data destroying bugs (either server or client side) in the code. For more information thought, you can head over to WhatPlanShouldIGet.uk

Categories
Electronics General

Moving to Android.

People that know me know I’m an “Apple Fan”. I’ve put that in inverted commas because I love my Apple stuff. I love how easy to use and good looking they are. I have a Mac as my main computer. An iPad. An iPhone. Apple TV. The list goes on.

I’m not the type, however, that likes to bash other peoples preferences. Just because I like something dosent mean everyone else should as well. I play with Ubuntu on my laptop. I mess around with the RasperryPi. I have a radxa. I still use Windows on both a Virtual Machine and in Bootcamp.

Recently, I’ve started to get frustrated using my iPhone 5. The phone itself is amazing, but it just lacked the customisability that I was after, so I decided to buy a Samsung Galaxy S5.

Now. Before I went out and bought a new mobile on a 24 month contract I figured it might be a good idea to have a play with Android first, then decide if a 24 month contract would work with a new device. After some asking around, I decided to swap my iPhone 5 for a Samsung Galaxy S4. In the whole, it was a fair trade, given that my iPhone had seen a few bumps and drops, and was definitely not in factory-fresh condition!

Samsung Galaxy S4
Samsung Galaxy S4

So. A Samsung Galaxy S4, with a free 32Gb memory card. I was sorted. What follows is my first week’s impressions.

Right away, I loved the screen size. Its bigger, but still as sharp. The device itself is light in the hand. I have an incase which protects it from my clumsy hands, which adds a bit of bulk, but its a reassuring bulk I’m more than happy with. The phone still fits in my pocket comfortably.

Setting up was a breeze and playing around with the settings and throwing some apps onto the device let me see how customisable the phone actually was. This is where I came across my first problem. I’m probably the only person who could complain about it being too customisable. By that I don’t mean the amount of settings or apps that can be installed and changed, I mean the inter-app connectivity. Certain apps just don’t work well together. Others require other apps to be installed when it looks like a simple bit of code could work in the main app. Being the way I am, I continued on and managed to get a decent set up that worked for me.

The next annoyance I had was the notifications. Android is renowned for its quality notifications, but I’ve became so used to the iPhone system of something popping up, swiping, and heading straight to that app. Again, where theres an issue, theres an app and there were a multitude there to take the iPhones lock-screen place. NiLS, cant do the “Swipe to unlock” per app as its a widget, and widgets don’t have the capability to read gestures. Full screen replacements work a lot better, but don’t integrate as well with the system when using a PIN Code to unlock (the main point for me was not changing the wallpaper to match the currently selected lock screen).

All in all, these are not the worst criticisms for a phone. I came to Android to see the difference, and I’m trying to set the device up as if its an iPhone. It’s all about changing my workflow.

Then a few software issues cropped up. Again, nothing too serious (well, the alarm not sounding was pretty annoying – good think I woke up early that day!) but just buggy.

The Alarm didn’t sound one morning. I couldn’t figure out why not until I went to change the alarm tone. There were no tones listed. No stock tones. Nothing, excluding one option which just unhelpfully stated “14”. Thats it. I then had a peek in message tones and ringtones, again, with the same “14” shown and nothing else. Wondering if I managed to delete ringtones from the device without realising, I downloaded an app which let me download ringtones, and after a few minutes, I had one ringtone set. I figured if it was a bug, adding a new ringtone should load the rest back up again, but I had no such luck. A quick power cycle seemed to clear this up. Not ideal.

Another annoyance is the two-photo app setup. Gallery, for all the devices images (and online albums from Facebook, Picasa etc) and Photos, for images from Google+. Why there is two apps I have no idea. Which lead me to an interesting discovery. The Gallery app would not show any images I had saved when browsing the internet via Chrome. I know I downloaded the images, I saw the little download bar, but I could find them anywhere on the system. Same with PDF files. I downloaded a few, and they opened fine from the download bar, but using Adobe Reader for Android gave me a “File is Corrupt” warning. Even though, I was reading them fine from the download app. After a bit of Google Searching, I discovered that the security permissions for Android had recently changed, which meant that UNIX style permissions were being enforced more stringently. This means that there was a chance that apps reading and writing to other app’s folders and files was a no no. I can see the positive argument for this, given that the system is so open its open to abuse, but I think giving the user the ability to revert back to the old “permission” system would work better.

And then there was the Amazon MP3 app. This app alone is worth of an entire blog post. In fact, its the reason i’m writing this post just now. I’m currently waiting on a 1.4Gb Samsung ROM to download to make sure I’m not going crazy.

The Amazon Cloud MP3 app works brilliantly, as long as your playing from the cloud. Thats not always the best option, and given my limited (and often breached) monthly data limit, not something I would like to do on a regular basis. Its a good thing that the app allows you to download for offline use! Well. At least its meant to. Hitting the download button on either a song or an album, I get to watch the progress bar fill up, followed by a nice big tick to say the song/album has downloaded. I also get a notification to tell me the song/album has downloaded. Hitting the song in the app after its downloaded unhelpfully reminds me that its streaming. Not a great start. Pressing the notification or going to the “Your Device” section in the app greets me with a wonderful “No Music on Your Device” message. Wonderful. No matter how many items I’ve downloaded. No matter how many times I’ve uninstalled, reinstalled, force closed, cleared the cache, and swore at the app, it does not have any music in the “My Device” Section.

Hooking the phone up to my computer and using the Android Transfer Tool, I can see in the Amazon MP3 folder all the music and albums I’ve tried to download. All the file sizes look correct. All the names are right. I just cant transfer them from the device. Its so frustrating that I factory-reset the device just to see if it was a bad setting somewhere (after an hour installing ADB in Ubutnu JUST to get a recovery menu started on the phone).


I wrote the above on May 28th, 2014 at 10:01, at 14:20.

Whats happened in the intervening 3 and a bit months? Well. I fixed the Amazon MP3 issue by conducting a complete re-install of the phone. That also fixed the ringtone issue. I keep the handset for 2 weeks, and I loved it. However I missed the integration. I have a few Apple TV’s, an iPad, a Mac Mini. My friends and family all have iPhones and/or iPads. I didn’t realise just how much I used AirPlay, or AirDrop. I loved the customisability of Android, but it also brought a lot of problems. Due to the sheer customisability of the software, small things were missed out (like the PIN lock screen mentioned above). These small were small annoyances, but annoyances all the same. The hardware and software wasn’t as well integrated as Apple. Again, small first-world problems, but problems all the same.

I eventually sold the Galaxy S4 on eBay for £185. I replaced it with a temporary iPhone 5C which another family member took out as an upgrade (but was still happy with the Galaxy S3 they had). As soon as the new iPhone is launched I’ll pass this handset back to its rightful owner, and make a my family a family of Apple Users.

Maybe I’m a real fan-boy after all?

Categories
Electronics General

Radxa Rock – Unboxing, setup and bootup

So I finally found a few minutes to set up my Radxa Rock. I’m still not to sure on how to say the name.

It’s a pretty nifty little machine. I’ll have to spend some time with the documentation to see exactly what I can make it do (or not!).

RRP-7The video is 18 minutes long, and in HD. It’s a good thing YouTube decided to increase the video limit to longer than 15 minutes!

due to its length, it may not play on mobile devices, or anywhere there isn’t a WiFi connection. If it’s needed, I’ll split it into two videos and re-post.

Enjoy.

 

Categories
Electronics Equipment Raspberry Pi

A case for my Raspberry Pi!

Heres a quick 7 minute video about a case I purchased for the Raspberry Pi that only cost £4 from eBay!

Categories
Electronics notes PHP

OSX 10.8.2 localhost directory & MySql / PHPMyAdmin

You know, just because it will bug me again at some point:

If for any reason you don’t want to use the “sites” folder for your web development, you can head to

/Library/WebServer/Documents

and upload code directly into your http://localhost folder.

to install PHPMyAdmin, just plop that PHPMyAdmin folder just downloaded right into the above folder.

To Install MySQL however, follow these steps:

Download the .dmg MySQL installed from MySQL.com

Run the first installed, then the auto-start installer, and finally the Preference Pane add-on.

Run this code in terminal:

sudo cp /etc/php.ini.default /etc/php.ini

and then load /etc/php.ini and replace any instance of

/var/mysql/mysql.sock

with

/tmp/mysql.sock

Start the MySQL server using the preference pane add-on, then run the following in Terminal:

/usr/local/mysql/bin/mysqladmin -u root password PASSWORD

Replacing PASSWORD with a password of your choice.

The last thing to do is head to the PHPMyAdmin directory, and copy the config.sample.inc.php to config.inc.php and edit that file, replacing the

$cfg['blowfish_secret'] = 'RANDOM BLOWFISH CHARACTERS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

RANDOM BLOWFISH CHARACTERS part with random characters!

Finally, head to http://localhost/phpmyadmin and your good to go!