Sunday, 26 June 2011

Monitoring a 3D Printer

I have tidied my new workshop and I am starting to play with 3d-printing again.

One of the ideas I've been thinking about for some time is remote monitoring of the printing process. Many prints can take several hours to complete and I don't have enough confidence to leave it alone for that long. Jumping up and down to check it every few minutes would quickly get annoying, so I wanted a way to control and monitor it from a web interface.

My plan is to use a few webcams to provide pictures of the bed, print, and overall mechanics, and an emergency stop button. Looking around, the best solution for webcam streaming on Linux (Ubuntu) is ZoneMinder - it can cope with streaming multiple webcams. I used apt-get to install it and there are some extra configuration required in the documentation. I can also point a couple of cameras out the window as a home-made CCTV/security solution.

After a bit of fiddling, I was able to get streaming webcam from my PS3 eye webcam: but the other three webcams refused to stream. This was a little odd, since I could happily get pictures using cheese, kamino, xawtv, and they all seemed to connect properly as /dev/video devices and appeared as v4l2 (VideoForLinux) devices. All drivers seemed OK and installed.
xawtv -c /dev/video0 -v 1 can provide useful information, such as the supported colour palettes.

Checking the zoneminder logs ( appearing in /tmp):
tail -f /tmp/zmdc.log 

24/06/11 22:14:03.046389 zmdc[2171].INF [Starting pending process, zmc -d /dev/video3]
24/06/11 22:14:03.047635 zmdc[2171].INF ['zmc -d /dev/video0' starting at 11/06/24 22:14:03, pid = 2869]
24/06/11 22:14:06.224901 zmdc[2171].ERR ['zmc -d /dev/video0' exited abnormally, exit status 11]
And I was also getting messages in
dmesg
[ 1929.678445] gspca: bandwidth not wide enough - trying again
[ 2529.745525] ohci_hcd 0000:00:0b.0: leak ed ffff880036a43730 (#85) state 2
Checking the USB devices looked OK:
davidr@hgwells:~$ lsusb 
Bus 002 Device 008: ID 046d:c049 Logitech, Inc. G5 Laser Mouse
Bus 002 Device 007: ID 056a:0013 Wacom Co., Ltd Graphire 3 4x5
Bus 002 Device 006: ID 05f3:0007 PI Engineering, Inc. Kinesis Advantage PRO MPC/USB Keyboard
Bus 002 Device 005: ID 0ac8:307b Z-Star Microelectronics Corp. USB 1.1 Webcam
Bus 002 Device 004: ID 05f3:0081 PI Engineering, Inc. Kinesis Integrated Hub
Bus 002 Device 003: ID 093a:2600 Pixart Imaging, Inc. Typhoon Easycam USB 330K (newer)/Typhoon Easycam USB 2.0 VGA 1.3M/Sansun SN-508
Bus 002 Device 002: ID 041e:4053 Creative Technology, Ltd Live! Cam Video IM
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 006: ID 05ac:1293 Apple, Inc. iPod Touch 2.Gen
Bus 001 Device 002: ID 1415:2000 Nam Tai E&E Products Ltd. or OmniVision Technologies, Inc. Sony Playstation Eye
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
davidr@hgwells:~$ 

but checking the USB tree shows that the 3 problem devices are only connecting in USB 1.1 (12M), and the one working device at USB 2.0 (480M).
davidr@hgwells:~$ lsusb -t
1-5:3.0: No such file or directory
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/8p, 12M
    |__ Port 2: Dev 2, If 0, Class=vend., Driver=zc3xx, 12M
    |__ Port 4: Dev 4, If 0, Class=hub, Driver=hub/4p, 12M
        |__ Port 2: Dev 6, If 0, Class=HID, Driver=usbhid, 12M
        |__ Port 2: Dev 6, If 1, Class=HID, Driver=usbhid, 12M
        |__ Port 3: Dev 7, If 0, Class=HID, Driver=wacom, 1.5M
        |__ Port 4: Dev 8, If 0, Class=HID, Driver=usbhid, 12M
        |__ Port 4: Dev 8, If 1, Class=HID, Driver=usbhid, 12M
    |__ Port 6: Dev 5, If 0, Class=vend., Driver=zc3xx, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/8p, 480M
    |__ Port 1: Dev 2, If 0, Class=vend., Driver=ov534, 480M
    |__ Port 1: Dev 2, If 1, Class=audio, Driver=snd-usb-audio, 480M
    |__ Port 1: Dev 2, If 2, Class=audio, Driver=snd-usb-audio, 480M
    |__ Port 5: Dev 6, If 0, Class=still, Driver=, 480M
    |__ Port 5: Dev 6, If 1, Class=vend., Driver=usbfs, 480M
Damn. It looks like I forgot the rule about mixing usb 1 and 2 devices - Plugging usb 1 and 2 forces everything on that hub to run as USB 1 (UPDATE : false).

Mixing around the ports, I still had problems. As a better solution, I've ordered a PCI-E USB 3.0 card and usb3 hub. Each port should  happily accept a 2.0 webcam, and should have plenty of bandwidth.
I usually use ebuyer.com, but in this case amazon.co.uk were a lot cheaper! (Usb3.0 card for £10 - hub for £20)

UPDATE:
It seems that the other cameras I had were, in fact, usb1.1 - (even though a couple were labelled as USB 2).  A later experiment with four identical USB 2.0 cameras had similar results.
The main problem does seem to be the USB bandwidth. Apparently cameras 'reserve' USB bandwidth (sometimes more than they use) and the usb 2.0 480Mb limit quickly gets used up. I'll post again after testing with USB3.0 (5Gb)