Hardware development

Protological is a site with a focus on hardware development including PCB design More »

Schematic capture

Ever wonder how to turn your idea into a physical product? More »

Hardware testing

Learn from our development mistakes. Look at that switch bounce! More »

 

Cross compile for Raspberry Pi, VideoCore, MMAL

I have a project which requires full control of the camera board on a Raspberry Pi from a custom C application, so I recently started looking into getting a toolchain and code running on the Pi. The Raspberry Pi is actually a really powerful and advanced SBC, with a full Broadcom VideoCore GPU and a connection to a 5MP camera that can do full 1080 HD video at 30 FPS. The project I am working on takes a single picture from the camera and saves it to the flash. I could use the raspistill application and some bash scripting, however I want full control over the camera and since eventually I will be processing video from a camera, the access should be as fast as possible by using the GPU. The first step was to build a tool chain and cross compiler to get things working, and then make a test application that uses the Multi-Media Abstraction Layer (mmal) library to access the VideoCore (VC) pipeline. I followed these two articles on how to use crosstool-ng to make a crosscompiler for the Pi. The next step was to make a simple application with some hooks into mmal and link it against the mmal libraries. It turns out the easiest way to build the mmal libraries is to clone the userland code for the Pi and build it locally using your new crosscompiler. I modified the cmake file in the makefile/cmake/toolchain/ directory to point to my custom crosstool-ng compiler rather than the compiler from git (Here are my modified buildme and cmake files).

Everything built successfully and the final step was to add in some mmal variables and function calls and build against the mmal libraries. This was more of a pain than I thought it was going to be. There are like 6 libraries that need to be preferences and 5 include paths for the VideoCore and mmal paths. After a few hours of searching and trial and error I found the correct include paths and library paths for GCC and the linker. One really annoying part was the fact that you have to explicitly add ALL libraries to the ld command, even if they are dependencies of libraries and the .so file is in the same directory as an already linked .so file. Take a look at this image and you will get the idea, all was fixed when I added -l entries for each missing lib. Here is what you need to build and link against if you want to access the camera on the Pi via mmal using VideoCore.

Include paths:
-I ../userland/
-I ../userland/build/inc/interface/vcos/
-I ../userland/host_applications/linux/apps/raspicam/
-I ../userland/host_applications/linux/libs/bcm_host/include/
-I ../userland/interface/vmcs_host/linux/
-I ../userland/interface/vcos/pthreads/
-I ../userland/interface/vcos/

Library include path:
-L ../userland/build/lib

Libraries to link:
-lmmal_core
-lmmal
-lmmal_util
-lvcos
-lcontainers
-lbcm_host
-lmmal_vc_client
-lmmal_components
-lvchiq_arm

Problems with cheap electronics on Ebay

I have an electric scooter project that has been on and off again for a while now, I get to it when I can when it’s not cooking or freezing in the garage.  The scooter runs on six 12V batteries for a total traction voltage of  60V, the lights/horn/blinkers/etc all run on 12v which requires a 60v to 12v DC/DC converter.  I found a cheap 72v to 12v converter on Ebay from a manufacturing company in China (similar to this one) and figured I would spend the $30 and see how it performed.  Well what I got in the mail wasn’t a DC/DC converter, but a 24v electric bicycle controller for a brushless DC motor.  The interesting thing is the mailing envelope had “Motor controller” on it and not “DC/DC converter”.  Here’s the new rule, you get what you pay for.  Because I’m sure sending a $30 unit back to China is going to be more trouble than it’s worth, I think I am going to keep the controller and maybe make an electric bike some day…if I can figure out the non-documented pin out of the thing!

Cheap electronics, wrong part sent from China

Microcontroller parameter parsing with AWK

I needed to get all the information on every 16bit Microchip PIC microcontroller into one header file for use in a library. Microchip supplies a pic.h header for processors but it doesn’t have the information I needed including end address of the flash and EEPROM. If you poke around on the Microchip parametric search site, you can select all 16-bit microcontrollers and download a CSV with all the parameters. A little bit of AWK magic and you can get a nice header with whatever data you want.

awk -f process.awk all-microcontrollers.csv > pic.h

AWK script and example output header

microchip microcontroller parameteric search

wxGlade Testing

I was playing around with python and a GUI for a simple plant watering setup I hacked together and I stumbled upon wxGlade. wxGlade is a GUI maker for wxWidgets and can output in C++, Lisp, Perl or python. So far it’s seems pretty cool, I just made a quick test with an image and some text boxes. Attached is the code with an extended class to implement functions.

wxglade_test.zip

wxglade

Serial LCD python code

A while ago I purchased a CFA533 TTL level serial LCD board from Crystalfontz for use with a project. The board has a 16×2 character LCD and 6 buttons with plastic pads arranged in a Dpad pattern. The unit talks serial at 19200 baud. I am ramping up for a new project so I decided to see what this little unit could do and how easy the command set is. The first order of business was to connect to the unit. I am not a fan of stripping tiny wires and soldering to headers, so I thought I would turn to the trusty CNC and make an adapter board. The LCD has a 5×2 header, takes 3.3v-5v, and since it is TTL it needs to interface with some serial adapter. I have a 5v FTDI 232R USB cable that would fit the bill for this, I also dug out some 10 pin ribbon cable, as well as numerous 5v wall transformers with 2.1mm barrel jacks. The board I came up with it pretty simple, 5V, GND, RX, TX all on a 2cmx3cm board.

The next step was to get it chatting with some software. I had some python code that was used a few weeks ago to talk to a PIC via serial so I thought I would modify that to talk the LCD protocol. The protocol is pretty simple, 1 byte for type/command, 1 byte for length, variable data payload and a 2 byte CRC16. The stumbling block came when I tried to compute the CRC16 for some commands. Python has always been a language where you could “import xxxx” and it just works, not so much with CRCs. The datasheet for the LCD says the polynominal used is 0x8408, I tried to use crcmod to define a generator however I kept getting errors about it being too short. Long story short, it appears that Crystalfontz is using a CRC that isn’t very common, so I took the example C in the LCD datasheet and made a simple python function which did the trick. I wanted to write this post so anyone else looking for this CRC could use it.

The final result is a quick command utility that allows python to control almost anything on the LCD.I also got the python running on a Raspberry Pi with pyserial installed. Here are some pictures of the effort as well as the Python code. py_basic_term.py

serial_lcd_pic serial_lcd_testing serial_lcd_interface raspberry pi serial lcd output

ESP8266 boards are in, time for a project

Oooh yeah I got 3 ESP8266 WiFi boards in the mail today from SeeedStudios.  Now lets make a project!  For those that don’t know the ESP8266 is a WiFi to serial board that is only $5-$6 USD.  Apparently the board does all the WiFi and ethernet stuff, so all your project has to do is some basic setup and then RX and TX.  I’ll be reporting on how easy this is here and posting any projects as well as code for microcontrollers.

Got my esp8266 boards today

Debounce switches with simple components

Lets start off with a post that dives into one of the uglier sides of electronics, switch bounce.  Every time a switch closes, mechanical contacts  (which are just pieces of metal) touch each other and complete the circuit. For a short period of time the contacts chatter and open and close the circuit, this is a real nightmare if you are looking for a clean on and off signal.  I ran into this issue with a set of limit switches for a CNC machine.  I decided to put one of the switches on a scope and see what the bounce time was.  Take a look at the scope trace below, as you can see there is about 1.5ms of bounce on these switches for both rise and fall.  It’s been a while since I debounced a switch outside of firmware, so I went off looking for some info, what I found was Jack Ganssle’s site with two pretty good articles on debouncing.  (While you’re there, check out his newsletter).  I dug through my parts bin and found a few 74HC14 schmitt inverters which can be used for debounce since they have a hysteresis between the high and low voltage levels.  Running through the equations on jacks page with a 5v supply, 0.1uF capacitor and a 2.37v high signal for the 74HC14 I came out with almost exactly 31K for the resistance.

I had a 33K resistor and a 0.1uF resistor so I hooked them up as per this schematic and left off the input resistor from Jack’s page and the rise time was just about 2ms. There are some other pages that discuss leaving off the input resistor so I decided to see if the response was acceptable.   You can see the schmitt inverter flips with a nice clean edge, switch debounced!

bouncing_scope_trace scope_rise_debounce scope_switch_debounce_output scope_proto_74HC14_debounce

Welcome to Protological

Protological is a site about electronics, DIY and software.  Our goal is to educate and share our experiences and projects with the world.  We will showcase projects from across the internet as well as posting information, schematics, code and documentation on our own development.  We also design electronics and we will offer our products via our online shop for purchase.

The major topics on Protological include:

  • PCB design
  • Microcontroller code
  • Prototyping
  • Electronic product development

Our goal is to have multiple posts per week in each of the major topics on the site as well as downloadable code and project files.  We will be documenting our progress at getting these posts out and pitfalls along the way.  As we get this site off the ground we would love support from the community, share your projects, hacks, mods and prototypes with us at info@protological.com and we will get them up on the site.

Happy building

Drew