Friday, October 7, 2016

Broken bits - CNC isolation milling and V-cutters

I buy inexpensive V-cutters for milling printed circuit boards (and recently switched to 20°, sharper ones). Often, the very end of the cutter breaks on the first contact with the copper layer (it is just so delicate). Usually I have either to compensate for the missing Z depth manually, or restart the job... else it will not carve enough and will not go through the copper layer.

From now on I think I will break the tip of the V-shaped mill bit myself before using one! Why?

V-cutter for milling PCB: pristine, slightly damaged and obviously broken. But the last one is my choice!

Wednesday, September 21, 2016

How to find a package in debian / ubuntu

Here are three different command I use to look for a linux package.
  • apt-cache search <regex>
  • apt-show-versions | egrep <regex>
  • dpkg -l | egrep -i <regex>
The first one is super verbose, but it lists all sub-packages.

The second one is a command to install via ''sudo apt-get install apt-show-versions''. I use it often as it also lists whether the package is already installed or not.

The last one I forget all the time. It will show which packages are, or were, installed on your system. It is concise and it lists the architecture (32/64 bits versions).

For example, here are the three output when looking for SDL dev (which stands for "simple direct media layer", a lightweight and cross-platform framework to develop graphics and access to low-level resources).

[11:35][jeremie@alpha:~] apt-cache search 'sdl.*-dev'
libsdl1.2-dev - Simple DirectMedia Layer development files
erlang-esdl-dev - Erlang bindings to the SDL (development files)
libalien-sdl-dev-perl - helper  to build  Perl program using SDL libraries
libghc-sdl-dev - Haskell SDL binding for GHC
libghc-sdl-gfx-dev - Haskell SDL gfx binding for GHC
libghc-sdl-image-dev - Haskell SDL Image binding for GHC
libghc-sdl-mixer-dev - Haskell SDL Mixer binding for GHC
libghc-sdl-ttf-dev - Haskell SDL TTF binding for GHC
libsdl-console-dev - Console that can be added to any SDL application, development files
libsdl-gfx1.2-dev - development files for SDL_gfx
libsdl-image1.2-dev - Image loading library for Simple DirectMedia Layer 1.2, development files
libsdl-mixer1.2-dev - Mixer library for Simple DirectMedia Layer 1.2, development files
libsdl-net1.2-dev - Network library for Simple DirectMedia Layer 1.2, development files
libsdl-ocaml-dev - OCaml bindings for SDL - development files
libsdl-pango-dev - text rendering with Pango in SDL applications (development)
libsdl-sge-dev - extension of graphic functions for the SDL multimedia, development files
libsdl-sound1.2-dev - Sound library for Simple DirectMedia Layer 1.2, development files
libsdl-stretch-dev - development files for SDL_stretch library
libsdl-ttf2.0-dev - TrueType Font library for Simple DirectMedia Layer 1.2, development files
libsdl2-dev - Simple DirectMedia Layer development files
libsdl2-gfx-dev - development files for SDL2_gfx
libsdl2-image-dev - Image loading library for Simple DirectMedia Layer 2, development files
libsdl2-mixer-dev - Mixer library for Simple DirectMedia Layer 2, development files
libsdl2-net-dev - Network library for Simple DirectMedia Layer 2, development files
libsdl2-ttf-dev - TrueType Font library for Simple DirectMedia Layer 2, development files
libtaoframework-sdl-cil-dev - Tao CLI binding for SDL - development files

[11:35][jeremie@alpha:~] apt-show-versions |egrep sdl.*-dev
libsdl-image1.2-dev:amd64/xenial 1.2.12-5build2 uptodate
libsdl-image1.2-dev:i386 not installed
libsdl1.2-dev:amd64/xenial 1.2.15+dfsg1-3 uptodate
libsdl1.2-dev:i386 not installed

[11:36][jeremie@alpha:~] dpkg -l | egrep -i 'sdl.*-dev'
ii  libsdl-image1.2-dev:amd64  1.2.12-5build2  amd64  Image loading library for Simple DirectMedia Layer 1.2, development files
ii  libsdl1.2-dev              1.2.15+dfsg1-3  amd64  Simple DirectMedia Layer development files
Thge ''ii'' flags mean here "currently installed", i.e. I already have them. You can read about other installation status flags here.

Thursday, September 15, 2016

Lightweight video streaming from a Raspberry with h264_v4l2_rtspserver

VLC adds 330Mo to a raspbian distribution just to stream video to the network. This is huge!
Instead there is a smaller solution, with adds "only" a few dozens megabytes of buliding tools (mainly).

It just interfaces the nice standard V4L2 driver and streams it to a RTSP feed (i.e. Real Time Streaming Protocol). This is also very efficient as minimum buffering is done locally, which means faster response time (time lag is "only" 2 seconds, which is decent).

From this answer.
sudo modprobe -v bcm2835-v4l2
git clone
cd h264_v4l2_rtspserver
sudo apt-get install libopus-dev libexpat1-dev libssl-dev libasound2-dev libudev-dev libavahi-client-dev libcurl4-openssl-dev libjs-jquery
cmake .
sudo make install
Then, the RTSP video stream can be accessed from anywhere with:
vlc rtsp://<raspberry>:8554/unicast

Note that ''h264_v4l2_rtspserver'' has a few options to optimize your bandwidth (reducing the network buffering helps also achieving a faster response time):
h264_v4l2_rtspserver --network-caching 300 -H <height> -W <width> -F <fps>

BTW some additional/alternative info for the Raspberry can be found here.

Wednesday, August 31, 2016

Optimize a C program by visually checking the profiling data

You need '''' (specific standalone tool) and the regular package ''dot'' (from graphviz).

g++ -pg -g myproc.cpp myproc
myproc myarg1 myarg2
gprof myproc | -s | dot -Tpng -o profiler.png

Note that the ''-g'' debugging option is required.

Note also that any code optimization flag, like ''-o3'' (aggressive speed optimization), will significantly impact the code layout, and it will be much harder to recognize the profiled sections.  It is much easier to read when most optimizations are tuned off (''-o1'' or ''-o0'').

But there is a nasty trade-off... Without optimization, the overall program will certainly behave differently than in production. It will not spend the same time in the same routines. Reciprocally, with full optimization you are closer to the real program you want to probe... but it will be sometimes just impossible to recognize the source code and unrolled functions that the profiler points to.

Monday, July 18, 2016

Why sending garbage is required before radio transmission (aka preamble for AGC radio receivers)

Sometimes there is a trade-off doing it "low level", but how much I learn everyday!

I eventually discovered, the hard way, why radio receivers with automatic gain control (AGC) do need compulsory seemingly "useless" preambles for them to adjust their volume properly, for the real data to come.

First: send a calibrating preamble (alternating zeros/ones)

No signal? The gain is adjusted to get one. So we read radio noise!
By the way, this radio module took about 30ms to fully adjust its gain.
Once I re-think about it, it is plain obvious... a receiver does not know whether someone is really transmitting or not. So when nothing is transmitted, it acts just as anybody on a audio system who wants to check if the source is plugged or not: the receiver increases the volume (gain) until it catches something. But when nobody really is transmitting, increasing gain eventually ends up amplifying noise, i.e. seemingly random 0s and 1s. As humans, we know we are hearing static and the input device is not transmitting. But the receiver is not able to know.

Without proper calibration, the start of real data then gets buried in the noise, until the receiver manages to set its gain, back to actual transmission levels (i.e. it reduces the amplification until signal is just below saturation -- again, like a human who quickly turns the volume down after the source is plugged).

Sunday, July 17, 2016

Power IoT devices with solar energy, the $1.50 cheap way!

Had to find an easy solution to power some of my low-power device, like the one on the right (it is a minimalist 433MHz receiver).

A long time ago I bought a bunch of solar flashlight keyrings specifically for scavenging the parts.

They proved to be better than my expectations, with a very convenient 37×22×1.1mm solar cell which gives 7V unloaded, and up to 8mA for tested loads of 1 and 100 ohms (it "rains fire" as we often say here in summer: specs are only 5.2mA~6.3mA at 3.4V~4.5V loaded).

Admittedly, it is not much, but it is enough for a great lot of IoT devices, and given the size, it is just GREAT.

Measuring tiny currents to assess power consumption

The original EEVblog ĀµCurrent (David Jones).
Way cheaper than real industrial probes,
but still too expensive for my needs ($80+)
Optimizing power needs requires power tools that can read tiny currents (nano or pico amperes)...

Nothing happened like I wanted to the last N days and had to work on unexpected stuff, like a remote water level alarm for our swimming pool after more leakages (the liner is 14 year old). So I made an RF alarm, which is powered by a small ultracapacitor (0.47F) backed by a tiny 3x2cm solar panel I scavenged from a led keychain.

I wanted it to be small, so I can duplicate the project and put sensors all around (I should end up at around 3x2x2 cm all included). But small means low power.

Friday, July 15, 2016

Tool to program an ATtiny85 AVR in situ in a minimalist configuration (ICSP)

Programming the chip, directly on the PCB (i.e. ICSP), via its shoulders.
Note how the pogo pins compensate for approximate placements!

Retractable pogo pins (top) and
regular 3x2 headers (bottom)

A long time ago, I made this little tool to help me upload code to Attiny85 AVR microcontrollers directly on the PCB (ICSP, i.e. in-circuit serial programming), but without even the need for a connector.

It plugs into regular 6 pin adapters of USB ASP programmers, and it relies on so-called elastic/retractable "pogo pins" to make contact with the DIP8 chip.

Saturday, July 9, 2016

Raspberry pi booting on a fullscreen web page (kiosk mode)

Start chromium at boot, while disabling screen savers

This is useful when you want a web application to be run straight out of booting process on a raspberry pi.

To start chromium in kiosk mode, without menus and cursor, use ''piconfig'' to boot into graphics mode and the ''pi'' user, then set the content of ''/home/pi/.config/lxsession/LXDE-pi/autostart'' to this:
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@xset s 0 0
@xset s noblank
@xset s noexpose
@xset dpms 0 0 0
xwit -root -warp $( cat /sys/module/*fb*/parameters/fbwidth ) $( cat /sys/module/*fb*/parameters/fbheight )
chromium-browser --app= --kiosk

You may use ''apt-get install unclutter'' instead of ''xwit'' above, to hide the cursor. Note: on NOOBS, ''.xinitrc'' does not seem to have any sort of effect, weirdly.

Hide booting process

When you want it to look more pro, you can redirect the boot process information to a secondary console, by changing ''tty1'' to ''tty2'' in ''/boot/cmdline''. You still can see it by pressing Control-Alt-F2 (then F7 to switch back to the grpahical terminal).

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty2 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline rootwait

Set the raspberry as an accesspoint

Finally, to set your raspberry pi as a wifi access point:

Lighttpd web server cgi-scripts

When you want lighttpd to be able to run a sudo cgi script, add this line with ''visudo'':
www-data ALL=(ALL) NOPASSWD: /var/www/cgi-bin/*

Thursday, March 31, 2016

Review: tiny Arduino Nano-based CNC shield

"Keyes_CNC" Arduino Nano shield for 4 axes CNC machines

The Keyes_CNC controller embarks an Arduino Nano
This little board is an "inverse" shield, on which an Arduino Nano must be plugged to provide functionality. It offers the same functionality as a regular Arduino Uno or Duemilanove CNC shield, with the same power.

But the result is both extremely compact and cheap: less than 7€ for the naked shield (or here), and about 22€/$25 for a complete setup: the shield plus an Arduino Nano and basic Pololu stepper drivers (here or there if you want ebay -- but the latter seems to be a reseller). And for once, it seems to come from a Chinese seller who designs and makes its own boards, which I tend to like.

Add a few Dupont wires (well, Jump wire is the generic name) and you are ready to go!
Fifteen years ago it would have cost thousands of euros!

A regular Arduino CNC shield has 4 axes
Important note 1: Even though 4 general purpose input/outputs are left to the user, this shield is not meant for 3D printing. It lacks a fourth axis (for the extruder). It has no support to read temperature inputs and has no power MOSFET or relays to drive the heaters. It is meant for 3-axis machines like CNCs, plotters and laser engravers.

Important note 2: the connectors are not meant to be abused. This is no industrial stuff, and there is no secure way to attach the steppers for example. As usual when a motor is disconnected while it is powered, back emf will generate a high current back into the board, which definitely can kill it. You do not want this to happen! This applies to all boards and all motors, but special care must be taken without better locking connectors.

Also, there is no documentation and GRBL does not come pre-installed. Hence this post.

Board pinout

I had to revert to my multimeter in order to double check the pin attributions.

Place the board in landscape view, with the power plug to the top left. You should be reading "Control by GRBL" in the center of the board in the correct orientation. Also, plug the arduino nano into the board so its USB plug goes to the right side of the board, as in the top picture in this post.

The silkscreen properly shows most of the signals, ground and power lines.

Here are the Arduino pins that control the outputs and the inputs of the board;

Note that the DIR signals are permuted with the STEP signals with respect to regular Uno CNC shields!

EN D8 (shared X,Y,Z)

EN D8 (shared X,Y,Z)

EN D8 (shared X,Y,Z)

CoolEN A3 (bottom row) and GND (top)
Resume A2 (bottom row) and GND (top)
Hold A1 (bottom row) and GND (top)
Abort A0 (bottom row) and GND (top)

E-STOP RST (bottom pin) and GND (top pin)

Generic extensions:

A7 From top to bottom: GND, 5V, A7
A6 From top to bottom: GND, 5V, A6

The SDA and SCL are part of so called I2C bus. These are very interesting for fast serial communication, where you talk to one or many slaves by referring to their "address" (use and I2C scanner to know the addresses if you need to). When you need many more input/output, you can use I2C "expander" chips like the MCP23017 (gives 32 more I/O) or PCF8574 (only 8 more I/O but with interrupt for when a slave wants to talk!).

Reciprocal view: here are the Arduino Nano pin attributions
RX0 $serial$
TX0 $serial$
D9 X- and X+ (endstops)
D10 Y- and Y+ (endstops)
D11 Z- and Z+ (endstops)
D12 [gpio]
D13 [gpio] / onboard LED
A0 Abort
A1 Hold
A2 Resume
A3 CoolEN
A4 $SDA$
A5 $SCL$
A6 [gpio]
A7 [gpio]

Power line for the stepper motors: a drawback!

The main power plug accepts up to 12V, but it always powers the Arduino Nano.

When the nearby jumper (named ''Mot_VOL_Sel'') is put in place, this power plug also powers the stepper motors. So there is no way to send 24V to the motor with the jack as you would burn the Arduino.

Reciprocally, without the jumper in place, the stepper can only be powered by the ''Mot_VCC'' and ''Mot_GND'' (common ground). These are unpopulated vias on the PCB, and located strangely far from each other on the top of the board.

The spacing between the two pairs of pins is 4 mm, and I found no connector to fit these pins and drill diameters. The best solution I found out is to solder thick wire directly to the board and add some gun glue to relief the cable. Not good.

Another solution could be to cut the trace between the power jack and the nano board, so as to leave the jumper in place and power the steppers from the jack (and the nano board from the USB plug, or from one of the many ''+5'' pins available on the board).

This is a pity as the remaining of the board is pretty nicely done. Some more routing and a footprint for a usual 2-pin screw terminal would have been easy to do in the first place, leaving a much better way to power the steppers independently of the Arduino board.

Flashing the GRBL software on the Keyes_CNC controller board

GRBL is a software initially designed for the Arduino ecosystem. It will run on this board exactly as on an Arduino Uno, since they have the same microcontroller inside. The pinout is slightly different though.

GRBL really is dedicated to efficient G-CODE interpretation. These are the data sent to 3D printers and CNCs alike. GRBL will convert the commands to stepper impulsions, and it will optimize the paths to take inertia into account.

Why use GRBL instead of the regular Arduino stepper library?

Indeed, you can also use this shield with the default Arduino stepper controller examples when you do not need to interpret G-CODES. This may happen also when you need more room for your own programming, as GRBL does not leave much memory!

The Arduino stepper libraries are quite inefficient compared to the dynamics of GRBL, which takes care of inertia and path optimization in your place. But they do the job and they are way easier to use if you just need to control small stepper motors, slightly loaded, or at slow speed.

Back to GRBL

Now that we know how to wire the board, we can tweak the GRBL configuration file. Note that even though GRBL can be uploaded very easily to your board, thanks to their little Arduino library that only uploads the binary to the board, it will not be possible here as it does not give the chance to depart from the default pinout!
You have to build it from source... This is slightly more complicated than a regular Arduino program because GRBL does not use the slow and bulky Arduino software ecosystem. Check the doc.

Saturday, February 13, 2016

PCB milling: how to verifiy the accuracy of routed traces

Inspecting an Eagle PCB milled board

Here is how I verify that my pcbgcode settings are good, and more precisely, how accurate the "etched" traces are, in relation to the depth of cut. The latter is not easy to set when using V-shaped mill bits, since the deeper, the wider the traces. The one below, between two pads is only 0.01 inch, i.e. 10 mils, and it was properly milled.

The trick was to overlay the live image from an USB microscope over the Eagle board design, scaling the windows appropriately. I applied 50% transparency to the webcam window (I am using ''cheese'' here), which is trivial with Kubuntu / linux. The microscope is an Andonstar, a great & cheap tool, for which I wrote a micro-review here.

By the way, I will no more use these "titanium" coated V mill bits, as they produce rough edges compared to the cheaper ones I bought earlier on ebay. This board is just ugly. Well, the PCB copper clad is also a super cheap one (I bought a lot "50Pcs 70 x 100 x 1.5mm FR-4 Single Side Copper Clad PCB Laminate Board" for $37 on ebay: I could not expect much but they are NOT FR4 but old style bakelite, not fiber glass! Much more fragile, not really worth).

Also my holes are slightly off-center, but not bad enough to be fatal here. Cheap 0.8 mm drills?

Review: the useful Andonstar USB microscope

The Andonstar USB microscope is definitely a great tool to double check surface mount components among other uses. I bought it from them on Amazon for about $70 (yep, it is not a low cost low quality USB endoscope).

Below I had to replace an AMS1117 regulator from a RAMPS that I blew (I plugged a 2-wire endstop to the wrong pair of 3-pin, which mean I grounded the power supply and got magic smoke...). I could then check how ugly I did ;)

The zoom range of an Andonstar USB microscope! And excellent tool for its price.
My main opinion is:
  • great wide zooming range (see the pic below)
  • integrated leds that are very close to the camera sensor (no external device would give enough light in the shot on the right given how close the lens is from the board)
  • the light intensity can be tuned down to zero. Sometimes the object is too reflective and it "flattens" the image. Then, an external lateral light beam is better.
  • a stable support with fast height adjustment (the stick can be raised/lowered quickly from the "main" tower) PLUS a fine thumbwheel on top of the camera barrel.

  • none really for the price
  • still the main pole has a bit of free play left, which can be felt when tuning with the thumb wheel at high zoom ratios (the small wheel is very firm). And there is no easy way to hack this.

Update: this slightly more expensive $85 version (A1-200W-B) addresses this with a definitive improvement. It uses the same microscope, but the already good stands looks way better. I would buy this one if I had to buy again.
The same USB microscope/endoscope but with an improved stand ($80 here)

Anyhow it is a must have in my opinion. I use it very often to inspect PCBs, to read SMT component values, or whenever my eyes are tired...

Final note: this microscope is featured in a video by Dave on EEVblog (a nice source of information by the way).

Wednesday, January 27, 2016

Funny Chinese counterfeit?

It makes sense... :D
Item: "3m Strong Permanent Double Sided Super Sticky Tape Roll"
Comment: "Counterfeit tape Not the real 3M tape by Scotch Knock off"
Banggood Reply: "Hello customer, this is not a 3M brand product, the 3m means 3 meters."

Review: arduino mega pro mini (aka Meduino)

This is a smaller variant of the Arduino Mega, and it is like what the Pro is to the Uno. It is even smaller than regular Arduino Uno boards, and costs about the same (less connectors, eh). And yes, it has all of what the Mega provides: extra memory & extra pins. And extra stuff to have in stock :)

Ref: check for "meduino" on ebay, or "mega2560 pro mini". There is also the "Mega2560-CORE mini" which needs and FTDI cable (no USB), and which is slightly cheaper. I bought the one below for $16 S&H included, and it took only 9 days from china to FR with tracking, impressive.

The Arduino Mega 2560 Pro Mini (aka Meduino) is a small factor regular Arduino Mega.