Raspberry PI IP webcam monitor

You can monitor a IP webcam with a RPI to a composite or HDMI screen pretty straight forwardly. This lets you decode a mjpeg stream which is a pretty common standard used by these IP cameras. The frame rate isn’t great for my setup but there are plenty of variables that might be causing that.

I setup the pi with some GPU fixes and the code which lets it dynamically manage it’s GPU ram. This appears to work pretty well. It also means I’ve plenty of ram for the other services. This stuff goes at the end of /boot/config.txt YMMV.

gpu_mem_256=112
gpu_mem_512=368
cma_lwm=16
cma_hwm=32
cma_offline_start=16

start_file=start_x.elf
fixup_file=fixup_x.elf

The following script is based on a number of sources. This is specifically designed to be robust for GPU/network/stream issues. OMX player can be a bit sensitive to poorly formed mjpeg streams.

while [ 1 ]
do
 tvservice -c 'PAL 4:3'
 echo deleting
 rm /tmp/stream.mjpeg -rf
 echo making
 mkfifo /tmp/stream.mjpeg
 echo getting
 timeout 14400 wget -c --timeout=1 -t 1 --http-user=xxxx --http-password=xxxx -O /tmp/stream.mjpeg 'http://xxx.xxx.xxx.xxx/videostream.cgi' &
 echo sleep
 echo startomx
 screen -dmS camera1 sh -c 'omxplayer --live --threshold 0 -r /tmp/stream.mjpeg; exec bash'
 wait 
 screen -X -S camera1 kill
 echo deleting
 rm /tmp/stream.mjpeg -rf
 echo finito
done
  • First the script ensures the composite output is live using the tvservice command (this is important for composite as the pi often shows a blank screen and needs it resetting), this would need adjusting or omitting for an HDMI screen.
  • Then it clears the existing fifo (if there is one) and creates a new one. Then it uses wget to connect the fifo to the camera stream. The timeout command automaticaly kills the wget command after 4 hours, this clears freezing problems I had at the expense of a couple of seconds while it restarts. You would need to change the URL so it works for your camera, this is for a foscam.
  • Then omxplayer is started in a screen session, this is to give it a live console (which it likes) and allows you to kill it later when wget has failed/been killed.
  • The wait command waits for wget to finish.
  • When wget is finished it kills the omxplayer session, deletes the fifo and starts again. It will repeat indefinitely.

Hopefully this helps someone out. It’s been a bit of a faff fixing all the little bugs with this. This script does appear to be fairly robust now though and it is a light enough method to coexist with motion for at least one camera. I have this script start up with the pi with no X window environment.

Read More

Upload AVR Assembler to an Arduino UNO

ArduinoAVRUploader – I’ve bundled the command bellow into a useful utility. The Arduino IDE must be installed for this to work. It’s developed in VS2013 so you might need to install a runtime.

A lot of the internet will tell you that you can’t program an arduino uno in assembler. You can can, but you can’t use the default IDE (which is fairly limited anyway). I didn’t work this out unaided but unfortunately I’ve forgotten where I found the info. Xloader was certainly a step along the way but sadly it doesn’t work with the uno (or at least the version I have).

You just need to compile you code to a .hex file using AtmelStudio and then run the command:

C:\Program Files (x86)\arduino\hardware\tools\avr\bin\avrdude.exe -C"C:\program files (x86)\arduino\hardware/tools/avr/etc/avrdude.conf" -patmega328p -carduino -P\\.\COM3 -D -U flash:w:"{path to your file}":i

This is how the Arduino IDE uploads its programs so it preserves the bootloader.

Read More

Coordinates to grid cells in Vorpal

Download gridCoords.mac

I’ve written a macro with a few useful functions to convert between coordinates (in meters) and cells (in…cells). It makes it a bit neater for those blocks which insist on being defined on the grid.

So something horrible like:

lowerBounds = [$int(floor((-XSTART-WG_A/2.)/DX))$ $int(floor((InWGCoupleOffSetY-YSTART)/DY))$ $int(floor(OutWGOffsetZ/DZ))$]

upperBounds = [$int(ceil((-XSTART+WG_A/2.)/DX))$ $int(ceil((InWGCoupleOffSetY-YSTART)/DY))+1$ $int(ceil((OutWGOffsetZ+WG_B)/DZ))$]

turns into something vaguely readable like:

lowerBounds = toGridFloorA(-WG_A/2.,InWGCoupleOffSetY+YSTART,OutWGOffsetZ)

upperBounds = toGridCeilA(WG_A/2.,InWGCoupleOffSetY+YSTART,OutWGOffsetZ+WG_B)

toCoords(x,dx,xstart) should convert the other way from cells to coordinates.

Read More

pyVorpal

PyVorpal-1.2.2

  • Uses VorpalDom
  • Extracts all or some blocks which can be plotted
  • Creates a Visit friendly .h5 file
  • There must be a .in file
  • VorpalComposer/VisIt can’t plot meshs with 0 or 1 cells in any dimension (at least on windows). As a workaround these are set to have 2 cells for plotting. It’s better than nothing for now.

With VorpalComposer you can integrate block plotting with the inbuilt visualisation. As the blocks are saved to an .h5 file as a mesh VorpalComposer lists the blocks as mesh’s and is able to plot them.

Plot the blocks as well as the fields in VorpalComposer

If you “Enable VisIt Context Menu” under “Visualisation Options” in Tools/Settings you can right click on the visualization pane and open the visit GUI. This lets you edit the colours and opacity of the plot.
Read More

Vorpal Blocks in VisIt

VorpalVisIt 0.11

  • Uses VorpalDom
  • Extracts all or some blocks which can be plotted
  • Creates a Visit friendly .h5 file
  • There must be a .in file and “”*_Globals_1.h5″.

Having become frustrated with Matlab’s inability to draw more than about 10,000 electrons without becoming unusable slow I thought I’d have a look at VisIt. It’s always nice to be able to plot the blocks from your .pre file so I thought I’d write something like VorpalPlotter to work with VisIt.

pmlSlabBlocks

pmlSlab example with blocks plotted

Read More

Vorpal In File to XML tree structure

VorpalDOM 0.1

  • Parses Vorpal .in files to a XML DOM structure using xml.etree.ElementTree
  • Block finding functions (by type and by name)
  • Scale class to convert between grid and length coordinate systems

With a little fiddling about, python’s built in XML packages can be used to parse the vorpal .in file. xml.etree.ElementTree only needs the block titles (“” for instance) to be altered to “” and a wrapping tag added (the equivalent of an “” tag) for it to be able to parse the file.

Read More