Project: Camera-Pi

Tell us about your projects. Update us regularly.
Post Reply
parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Project: Camera-Pi

Post by parkview » Tue Apr 07, 2020 2:22 pm

I have had a bit of a hunt through past posts, but I don't see any references to this project. A bit hard to believe that I have missed blogging about it as it's appeared in a few SW Maker meeting blog posts (http://www.swmakers.org/blog/sw-makers- ... ie-meeting).

Anyway, a few years ago when I was sitting out in the bush over a rainy winter, I wondered if Helmet Orchid flowers might have a preferred opening direction, ie: does the flower like to open say pointing to the East, South, West or North, or is it random?

I thought (for me), it would be easier and more fun building a simple Raspberry Pi camera rig to test this hypothesis, and so the Camera-Pi project was born.

The hardware centres around a Raspberry Pi Zero W (wireless), a 3D digital compass and a GPS, all of which I have at hand The idea being that I will rotate the camera to align with the flower opening and then press a button to take a photo and record the digital compass reading. The data will be stored in a CSV file and inserted into the JPG EXIF data.
Project Block Diagram sml.jpg
Project Block Diagram sml.jpg (17.8 KiB) Viewed 1502 times

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Tue Apr 07, 2020 2:44 pm

Back in May 2018, I whipped up a KiCAD (https://kicad-pcb.org/) design for the central electronics board and had it manufactured. There it sat for two years, as I was too busy working on other projects. Now that I have some spare time, I dusted off the PCB's and assembled one of them after laser cutting out a Mylar solder paste stencil:
Camera-Pi V1.0 PCB.jpg
Camera-Pi V1.0 PCB.jpg (93.5 KiB) Viewed 1501 times

Above, I have fixed up a few PCB layout errors and on the left hand side I am experimenting with a new LED flash light control circuitry. Luckily I had placed some spare 0805 pads for this kind of expansion.

I had previously designed up and laser cut out a base for all the boards:
Camera-Pi V1.0.jpg
Camera-Pi V1.0.jpg (79.38 KiB) Viewed 1501 times

I even 3D printed some customised M2.5 bolt stand-offs to help hold it all together. You can see two 1W white LEDs floating between the compass and GPS boards. I designed and 3D printed up the 18650 battery holder (https://www.thingiverse.com/thing:2878464) and this has been a success. It includes a handy finger hole underneath to help push the battery up for removal.

As it stands this has enough features for me to start coding up the software in Python and using a PyGame (https://en.wikipedia.org/wiki/Pygame) graphical interface via /dev/fb1 which still gives me access to the console via HDMI, although I usually just SSH to the RPi and write my code using the VIM editor.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Tue Apr 07, 2020 2:59 pm

While I was testing out the extra LED Flash circuitry, I thought I might as well create a new version of the PCB and have a go at designing up my own battery voltage booster circuit based around the LM2623 IC. This will allow me to drop the Adafruit Booster board. I do have lots of spare room on the PCB, and I added a INA219 current/voltage sensor, so I can be in control of monitoring the battery usage. This will allow me to post battery low warning shut down the board when the battery gets too low.

From resent testing I get at least 6 hours of use with the LCD and WiFi switch on. This means it should last about the same, or maybe a bit longer with the WiFi off and using the camera and flash LEDs.
Camera-Pi_board_V2.1.jpg
Camera-Pi_board_V2.1.jpg (124.7 KiB) Viewed 1501 times

The new version of the board is now a lot more complex and has been sent off for manufacturing. It does include two different methods of switching an array of parallel 1W white flash LEDs and a choice of two buzzers.

The large void on the left hand side is for a 26 pin TFT LCD 320x240 display cable. It saves having to try and create a 100% error free 26pin socket placement alignment.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Fri Apr 10, 2020 2:11 pm

Whoops, bit of a setback on the PCB design.

While I tested each section of the design, I didn't fully test the full functionality of all the components working at the same time. At that stage, I hadn't really worked out a code design. I just knew I had previously written code for each section via older projects. Turns out I had placed some of the switches and a LED on the RPi SPI bus pins.

A few days ago I wrote tests for each section, ie: switches, LEDs and the LCD display. It all worked well. Yesterday I started working on integrating it all together and strange things started to happen. At first it didn't click that it was hardware, so I spent some time examining my code. Turns out once the switch code loaded, the screen would stop working. At that stage I was testing some new technique of copying the HDMI framebuffer: /dev/fb0 over to the LCD framebuffer: /dev/fb1 It took a while to come to the realisation that it was a hardware issue, but once diagnosed, it didn't take long to disassemble the board and re-route the inputs. No wonder the LED would mysteriously start blinking dimly.

Front:
re-wiring_sml1.jpg
re-wiring_sml1.jpg (79.27 KiB) Viewed 1493 times

and backside (through the dayglow acrylic backplane):
re-wiring_sml2.jpg
re-wiring_sml2.jpg (46.51 KiB) Viewed 1493 times
Unfortunately this was all discovered after the next revision of the PCB has been sent off for manufacturing. Version 2.1 of the PCB is now in the mail back to me. I have updated the PCB layout to include these changes, but unless something major is found to be wrong with V2.1, I will live with these small hand modifications.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Fri Apr 10, 2020 2:27 pm

I love writing Python Pygame interfaces for my projects. It's a very handy GUI software package. Once I had resolved the above hardware wiring issues, it didn't take long to adapt my previous Orna project code to fit this project. I even managed to create some transparent PNG image icons for my battery and wifi status:
shutdown-screenshot_2020-04-09_230450.jpg
shutdown-screenshot_2020-04-09_230450.jpg (4.16 KiB) Viewed 1493 times
One interesting issue has been getting Pygame to write to the /dev/fb1 framebuffer. Most things want to write to the default /dev/fb0 framebuffer, which is what the main console (HDMI output), uses. There is a nifty small program called 'fbcp' and this will conveniently copy any going to fb0 to fb1. At the moment, it doesn't look like I can force the picamera software to write the camera preview directly to fb1, so I will have to call fbcp to do the live preview.

On the blue status bar I will be displaying 1) a count of photos take, 2) E = GPS error, 3) wifi on/off status, 4) battery status in 25% increments. This might all change as I use it more.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Sat Apr 11, 2020 9:42 am

Yesterday I spent some time examining the Python Compass code, then in the afternoon I attempted to get the camera live preview up onto the LCD. I decided to learn how to run 'fbcp' in a separate thread, but after reading up on threads and trying out some code, I realised there is no Python method to terminate a thread. In the end I reverted back to spawning a new process to run the 'fbcp' program just before I start the picamera function. I record the PID of the process and then use 'os.kill' to terminate the spawned process. This seems to work well, even if the main program crashes, Linux will remove any spawned processes after the crash.

Once I have taken a photo, I have PIL resize the photo down to around 300 x 240 and write the compass angle onto the screen and then display the photo onto the screen:
shutdown-screenshot_2020-04-10_230236.jpg
shutdown-screenshot_2020-04-10_230236.jpg (14.08 KiB) Viewed 1492 times

Just a photo of another projects BOM. It's a bit blurry as the camera protective cover plastic is still in place.

parkview
Master Maker
Posts: 450
Joined: Tue Jun 24, 2014 8:25 pm
Location: Busselton
Contact:

Re: Project: Camera-Pi

Post by parkview » Sun May 31, 2020 11:17 am

The new Camera-Pi version 2.1 arrived the other day. I laser cut out a 0.1mm thick solder stencil and hotplated the components on:
camera-pi-v2.1_PCB_sml.jpg
camera-pi-v2.1_PCB_sml.jpg (51.75 KiB) Viewed 806 times

This PCB now has a 3V to 5V at up to 2A voltage boost circuit on the PCB. This will allow me to easily monitor the battery voltage and current via an i2c based INA219A IC. After soldering on the 40pin RPi header and the 26pin display cable adaptor I successfully powered it up. I also had to make the four PCB trace modifications that I found out after I had sent off the

In the photo below you can see that the lower left hand battery boost board has been removed from the acrylic base plate as it's no longer needed:
camera-pi-v2_sml.jpg
camera-pi-v2_sml.jpg (46.77 KiB) Viewed 806 times

Next up is more software testing.

Post Reply