Beaglebone Green - Experience and Notes

mount them.

Field definitions

/etc/fstab contains the following fields separated by a space or tab:

<file system>   <dir>   <type>  <options>       <dump>  <pass>
  • - defines the storage device (i.e. /dev/sda1).

  • - tells the mount command where it should mount the to.

  • - defines the file system type of the device or partition to be mounted. Many different file systems are supported. Some examples are: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The ‘auto’ type lets the mount command to attempt to guess what type of file system is used, this is useful for removable devices such as CDs and DVDs.

  • - define particular options for filesystems. Some options relate only to the filesystem itself. Some of the more common options are:

    • auto - file system will mount automatically at boot, or when the command ‘mount -a’ is issued.

    • noauto - the filesystem is mounted only when you tell it to.

    • exec - allow the execution binaries that are on that partition (default).

    • noexec - do not allow binaries to be executed on the filesystem.

    • ro - mount the filesystem read only.

    • rw - mount the filesystem read-write.

    • sync - I/O should be done synchronously.

    • async - I/O should be done asynchronously.

    • flush - specific option for FAT to flush data more often, thus making copy dialogs or progress bars to stays up until things are on the disk.

    • user - permit any user to mount the filesystem (implies noexec,nosuid,

  1. installing flask/ flaskio, etc.

pip install …

  1. web camera

A clean install of a new bbg image and opencv lead to good results.

IM using an ELP- ELP-USB500W05G-FD100 USB camera. The minimum resolution is 640x480@ 30fps.

using the following to get images form the camera and encode the data (after opencv decodes it) yields about .06sec per image (15 fps) with about 1-2 sec lag between realtime and the image displayed in a browser. (@640x480, 50% jpeg quality)
I don’t know why it makes sense to go form a jpeg stream (mjpeg) to raw data the back to jpegs, but that is an openCV limitation for now.
code grabbed and modified from (Website: http://www.chioka.in/)

I think the BBG is not well suited for this type of use, but it will be ok.

import cv2
import time
class VideoCamera(object):

def init(self):

Using OpenCV to capture from device 0. If you have trouble capturing

from a webcam, comment the line below out and use a video file

instead.

self.video = cv2.VideoCapture(0)
print( 'camera initialized? ', self.video.isOpened())
self.video.set(3,640)
self.video.set(4,480)
self.video.set(5,30)

If you decide to use video.mp4, you must have this file in the folder

as the main.py.

#self.video = cv2.VideoCapture(‘video.mp4’)

def del(self):
self.video.release()

def get_frame(self):
#before = time.clock()
success=self.video.grab()
success,image = self.video.retrieve()

We are using Motion JPEG, but OpenCV defaults to capture raw images,

so we must encode it into JPEG in order to correctly display the

video stream.

encodeoptions =[cv2.IMWRITE_JPEG_QUALITY,50]
ret, jpeg = cv2.imencode(’.jpg’, image,encodeoptions)
#print time.clock()-before
return jpeg.tostring()

added thefollowing ot get it to work the second time

root@beaglebone:/sys/devices/platform/bone_capemgr# echo BB-UART1 > slots
root@beaglebone:/sys/devices/platform/bone_capemgr# echo BB-UART2 > slots
root@beaglebone:/sys/devices/platform/bone_capemgr# echo BB-UART3 > slots
root@beaglebone:/sys/devices/platform/bone_capemgr# echo BB-UART4 > slots
root@beaglebone:/sys/devices/platform/bone_capemgr# echo BB-UART5 > slots
root@beaglebone:/sys/devices/platform/bone_capemgr# ls
baseboard driver_override of_node slot-4 slot-6 slot-8 subsystem
driver modalias power slot-5 slot-7 slots uevent
root@beaglebone:/sys/devices/platform/bone_capemgr# cat slots
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,BB-UART1
5: P-O-L- 1 Override Board Name,00A0,Override Manuf,BB-UART2
6: P-O-L- 2 Override Board Name,00A0,Override Manuf,BB-UART3
7: P-O-L- 3 Override Board Name,00A0,Override Manuf,BB-UART4
8: P-O-L- 4 Override Board Name,00A0,Override Manuf,BB-UART5
root@beaglebone:/sys/devices/platform/bone_capemgr# dmesg | grep ttyO

ref link
https://billwaa.wordpress.com/2014/10/02/beaglebone-black-enable-on-board-serial-uart/


| RobertCNelson |

Auto Generated Inline Image 1.png



6/12/14
|

  • | - | - |

Hi Again

I try this configuration on /boot/uEnv.txt
optargs=capemgr.enable_partno=BB-UART1,BB-UART2,BB-UART4

but it doesn’t work.

The only way I could do this, is by using this command
echo BB-UART2 > /sys/devices/bone_capemgr.*/slots

Can someone explain me why ?

probally the wrong “uEnv.txt”

dmesg | grep console

would prove that

  • show quoted text -

Accidentally starting over. Re-flashed emmc, forgot to comment out command in uEnv.txt (pwm stopped working did not understand why)
steps to get back in business checking each step to see what altered pwm
VERSION

uname -a

Linux beaglebone 4.4.30-ti-r64 #1 SMP Fri Nov 4 21:23:33 UTC 2016 armv7l GNU/Linux
UPDATE apt-get database

apt-get update

REMOUNT EXT SD CARD
# mkdir /extsd
# mount /dev/```mmcblk0p1 /```extsd``

vi /etc/fstab

/dev/mmcblk0p1 /extsd ext4 defaults 0 0
reboot and check
SETUP UART

vi /boot/uEnv.txt

cape_enable=bone_capemgr.enable_partno=BB-UART1,BB-UART2,BB-UART4, BB-UART5
modifying the uEnv.tx file causes the pwm pin mapping to become lost)
Modified uEnv again to add pin 16 (EHRPWM1A from pin layout) it works

vi /boot/uEnv.txt

cape_enable=bone_capemgr.enable_partno=BB-UART1,BB-UART2,BB-UART4,BB-UART5,BB-EHRPWM1A
Upgrade installed packages (takes a while)

# apt-get upgrade

Reset - retest pwm (pin16), test UART, pwm failed again ater upgrade(ValueError: Error initialising PWM on pin)
cape_enable=bone_capemgr.enable_partno=BB-UART1,BB-UART2,BB-UART4,BB-UART5,PyBBIO-ehrpwm1

Just had a WTF moment.

I was working on a BBG image that was still on an sd card. and it appears as if pwm and uart pins are all properly configured out of the box.
This was definately not the case on the flashed version.

Still trying to figure out if UART actual is working out of the box, it appears it is untill i try to communicate with my camera. Going to try the minicom test.
On reset the ttyO1…O5 disappeared.
DOest not work out of the box
back to fixing pwm

brightness (int) : min=-64 max=64 step=1 default=0 value=0
contrast (int) : min=0 max=64 step=1 default=32 value=32
saturation (int) : min=0 max=128 step=1 default=64 value=64
hue (int) : min=-40 max=40 step=1 default=0 value=0
white_balance_temperature_auto (bool) : default=1 value=1
gamma (int) : min=72 max=500 step=1 default=100 value=100
gain (int) : min=0 max=100 step=1 default=0 value=0
power_line_frequency (menu) : min=0 max=2 default=1 value=1
white_balance_temperature (int) : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
sharpness (int) : min=0 max=6 step=1 default=3 value=3
backlight_compensation (int) : min=0 max=2 step=1 default=1 value=1
exposure_auto (menu) : min=0 max=3 default=3 value=1
exposure_absolute (int) : min=1 max=5000 step=1 default=157 value=157
exposure_auto_priority (bool) : default=0 value=1
brightness (int) : min=-64 max=64 step=1 default=0 value=0
contrast (int) : min=0 max=64 step=1 default=32 value=32
saturation (int) : min=0 max=128 step=1 default=64 value=64
hue (int) : min=-40 max=40 step=1 default=0 value=0
white_balance_temperature_auto (bool) : default=1 value=1
gamma (int) : min=72 max=500 step=1 default=100 value=100
gain (int) : min=0 max=100 step=1 default=0 value=0
power_line_frequency (menu) : min=0 max=2 default=1 value=1
white_balance_temperature (int) : min=2800 max=6500 step=1 default=4600 value=4600 flags=inactive
sharpness (int) : min=0 max=6 step=1 default=3 value=3
backlight_compensation (int) : min=0 max=2 step=1 default=1 value=1
root@beaglebone:/var/lib/cloud9# v4l2-ctl --device=/dev/video0 --set-ctrl=exposure_auto=0
VIDIOC_S_EXT_CTRLS: failed: Invalid argument
Error setting controls: Invalid argument
root@beaglebone:/var/lib/cloud9# v4l2-ctl --device=/dev/video0 --set-ctrl=exposure_auto=6
VIDIOC_S_EXT_CTRLS: failed: Numerical result out of range
Error setting controls: Numerical result out of range
root@beaglebone:/var/lib/cloud9# v4l2-ctl --device=/dev/video0 --set-ctrl=exposure_auto=4
VIDIOC_S_EXT_CTRLS: failed: Numerical result out of range
Error setting controls: Numerical result out of range
root@beaglebone:/var/lib/cloud9# v4l2-ctl --device=/dev/video0 --set-ctrl=exposure_auto=3
root@beaglebone:/var/lib/cloud9# v4l2-ctl --device=/dev/video0 --set-ctrl=exposure_auto=3

openvcv video capture is very slow 8 fps

  • 0-CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds or video capture timestamp.
  • 1-CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
  • 2-CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
  • 3-CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
  • 4-CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
  • 5-CV_CAP_PROP_FPS Frame rate.
  • 6-CV_CAP_PROP_FOURCC 4-character code of codec.
  • 7-CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
  • 8-CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
  • 9-CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
  • 10-CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
  • 11-CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
  • 12-CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
  • 13-CV_CAP_PROP_HUE Hue of the image (only for cameras).
  • 14-CV_CAP_PROP_GAIN Gain of the image (only for cameras).
  • 15-CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
  • 16-CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
  • 17-CV_CAP_PROP_WHITE_BALANCE Currently not supported
  • 18-CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

Finally some what of a break through,

Using OpenCv for just capturing a web cam seems wasteful and it doesn’t work well with the software decoding and re encoding jpegs from a mjpeg stream. Also all the steps to set up pwm pins a / uart pins on the beaglebone that Ive take to date seem to start other problems.

For web cam capture via a USB camera I found a v4l2 library that makes it fast and simple. Install the v4l2capture library, it takes a few iterations to get all the dependencies installed. see the camera script and web server example pasted below.

for pin control i’ve been leaving the uEnv.txt file alone and using the univeral(x) cape manager and config-pin (ex config-pin -a P9.24 uart) to set pin function. there are still quirks and you have to reset pins on reboot, but its been manageable. for instance if you load the cape manger overlay directly it doesnt always work, but if it loads itself after finding its not loaded when executing config-pin - a Px.xx nnnn it works fine, also if you run config-pin -a to set a pin to uart it auto loads cape-universal which doesnt let some pwm pins work, so its best to get universala loaded first as one does not replace the other and I’m not sure they can be unloaded with out cycling power.

https://github.com/cdsteinkuehler/beaglebone-universal-io

#camera.py

import select
import v4l2capture
import time
class VideoCamera(object):
#globals for testing
size_x=0
size_y=0

intitialize

def init(self):

grab camera

self.video = v4l2capture.Video_device("/dev/video0")
#set format the python version of v4l2 and v4l2capture API’s are not the great
size_x, size_y = self.video.set_format(640, 480, fourcc=‘MJPG’)
print (‘size :’,size_x,size_y)
#create a memory buffer for the jpgs
self.video.create_buffers(1)
self.video.queue_all_buffers()

start the vidoe capture process

self.video.start()

destructor

def del(self):
self.video.close()

capture image

def get_frame(self):
#before = time.clock()
#not sure what select.select is doing
select.select((self.video,), (), ())

read and queue set the motion so to speak, with read alone you only get the first image on start

jpeg = self.video.read_and_queue()
#print 1/(time.clock()-before)
return jpeg
#!/usr/bin/env python

main.py

Project: Video Streaming with Flask

Author: Log0 <im [dot] ckieric [at] gmail [dot] com>

Date: 2014/12/21

Website: http://www.chioka.in/

Description:

Modified to support streaming out with webcams, and not just raw JPEGs.

Most of the code credits to Miguel Grinberg, except that I made a small tweak. Thanks!

Credits: http://blog.miguelgrinberg.com/post/video-streaming-with-flask

Usage:

1. Install Python dependencies: cv2, flask. (wish that pip install works like a charm)

2. Run “python main.py”.

3. Navigate the browser to the local webpage (ex 192.168.8.100:5000).

from flask import Flask, render_template, Response
from camera import VideoCamera
import time

app = Flask(name)

@app.route(’/’)
def index():
return render_template(‘index.html’)

def gen(camera):

the timestart variable is an attempt to limit calls to get a camera frame 1/.0333 (30) times per second to match the camera limit

timestart =time.clock()+.033333
while True:

if time.clock() > timestart:
timestart=time.clock()+.033333
frame = camera.get_frame()
yield (b’–frame\r\n’b’Content-Type: image/jpeg\r\n\r\n’ + frame + b’\r\n\r\n’)

@app.route(’/video_feed’)

def video_feed():

return Response(gen(VideoCamera()),
mimetype=‘multipart/x-mixed-replace; boundary=frame’)

if name == ‘main’:
app.run(host=‘0.0.0.0’, debug=True)

me (Chris M change)


|

Auto Generated Inline Image 1.png



7:43 PM (46 minutes ago)
|

  • | - |

Restarting going to use universala for uart, pwm, and gpio (MRAA and ADAFruit_BBIO both work in python)

web cam will be using python-v4l2capture

VERSION

uname -a

Linux beaglebone 4.4.30-ti-r64 #1 SMP Fri Nov 4 21:23:33 UTC 2016 armv7l GNU/Linux
UPDATE apt-get database

apt-get update

REMOUNT EXT SD CARD
# mkdir /extsd
# mount /dev/```mmcblk0p1 /```extsd``

vi /etc/fstab

/dev/mmcblk0p1 /extsd ext4 defaults 0 0
reboot and check

INSTALL PACKAGES

# apt-get upgrade

installing v4l2capture

git clone https://github.com/philips/libv4l

cd libv4l

make

#make install

install v4l2capture

git clone GitHub - jnohlgard/python-v4l2capture: Python extension to capture video with video4linux2 (fork of https://launchpad.net/python-v4l2-capture)
python-v4l2capture uses distutils.
To build: ./setup.py build
To build and install: ./setup.py install

pip install pillow

Starting over severl months later.

I have let this sit for too long. I dont remember all the steps taken to get torodot running.

Starting over.

  1. update and upgrade apt get.
# apt-get update
# apt-get upgrade
  1. found a copy of the robot python files not sure what version they are. copied zip file into cloud 9 directory. (see attached)

apt-get install unzip

apt-get install zip

example.zip (149 KB)

several months later.

I have let this sit for too long. I don’t remember all the steps taken to get the robot running.
using the i/o direct from the beaglebone green input/output seems to fry the board randomly. i had bought some optoisolators but never used them… too large. The beagel bone io is problematic many cannot be used or mapped correctly.
Starting over.

  1. update and upgrade apt get.
# apt-get update
# apt-get upgrade
  1. found a copy of the robot python files not sure what version they are. copied zip file into cloud 9 directory. (see attached)

apt-get install unzip

apt-get install zip

unzip example.zip

The main program is app.py (i think)
First run says flask-socket i/o not installed.
3) install flask socket io
get the latest pip version

pip install --upgrade pip

install socketio (fast install)

# pip install flask-socketio

Second run attempt askes for gevent
4) install gevent

pip install gevent (takes several minutes)

third run needs v4l2capture

  1. install v4l2capture
installing v4l2capture

git clone https://github.com/philips/libv4l

cd libv4l

make

#make install

install v4l2capture

git clone https://github.com/gebart/python-v4l2capture
python-v4l2capture uses distutils.
To build: ./setup.py build
To build and install: ./setup.py install

Now it runs… not sure if everything works, but the camera is sending video.