Beaglebone Green - Experience and Notes

601 views
Skip to first unread message

Chris M

unread,
Nov 13, 2016, 5:09:06 PM11/13/16
to BeagleBoard
Some thoughts and findings as I begin to learn the BBG (Beaglebone Green)

Chris M

unread,
Nov 13, 2016, 5:24:56 PM11/13/16
to BeagleBoard
1) The first tutorial blinking the four onboard leds.

I did the tutorial using bonescript and also by using echo > at the prompt to change the corresponding files ( /sys/class/leds/beaglebone\:green\:usrx)
 
ISSUE FOUND:
One thing I wrestled with was the leds by default do not follow the predescribed operational pattern.  Echoing "none" to the trigger files and other changes to the bonescript did not have any affect.
The leds would continue to alternate 1,3 lit then 2,4 lit.   It was obvious that something else was writing to the leds and was interfering with the tutorials.

SOLUTION:
I found that if I connected to the BBGw with my phone and clicked "done" every time the BBGw is turned on or reset, the leds would then go back to their stated mode of operation. and allow the tutorials to work properly.

End entry 1.

Chris M

unread,
Nov 13, 2016, 5:45:24 PM11/13/16
to BeagleBoard
2) playing with stepper motors.

I hooked up a nema 17 stepper motor via a DRV8825 Stepper Motor Driver basically using the same led tutorial bone script to drive the GPIO pins to run it.

The DRV8825 current limit instructions and youtube videos are unclear how to set up.  I learned the hard way and wrecked a few of them in the process. The way i found to set them up was to wire them up completely under no power (make sure to use the 3.3VDC power from the BBG and do not use the 5VDC) with the motor disconnected.  Then power them up first the BBG then the external power supply for the stepper motor. Then the correct voltage between the ground (common BBG and external PS) and the potentiometer cover can be read.) I set the voltage to .6VDC for testing.

ISSUE FOUND:
Bonescript is not really fast enough or even intend to run stepper motors by togging the pin outputs. Even at slow speeds there would be numerous missed steps and poor behavior. My oscilloscope showed this to be true at the BBG and not after the DRV8825.

SOLUTION:
Don't us bonescript.  Now the fun begins, next try Python.

End Entry 2



On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 13, 2016, 6:05:02 PM11/13/16
to BeagleBoard

3) playing with stepper motors - Python


My next try was to use python as there are many included examples with the Cloud9 IDE.

ISSUE FOUND:
Importing the BBIO library causes the python program to crash. Apparently, BBIO is not yet compatible with the linux kernel (4.x) the BBG ships with. Almost all the python tutorials rely on BBIO and there most are broken.

SOLUTION:
I did not try using an older beaglebone image as I was worried it would loose the WIFI functionality of the BBG. instead I tried using the MRAA library in python

import mraa #Python script





On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 13, 2016, 6:33:58 PM11/13/16
to BeagleBoard

4) playing with stepper motors - Python


I first mimicked the bonescript to us the GPIO pins to run the stepper motor.  I noticed I could run it faster than I could with bonescript, but would still get the same issues just at better speeds. I then tried setting the pin to run as a PWM output.

ISSUES FOUND:
USING GPIO is not a good solution for running stepper motors.

Issuing the mrraa.write(0.xx) would cause a buffer overrun when setting the PWM duty cycle and crash the program,
Using pin.pulsewidth_us(xxx), pulsewidth_ms(xxx), or pulsewidth(x.xx) to set the duty cycle directly would work, but when values got out of range the pwm chip would become locked requiring the BBG to have to be reset..

SOLUTION:

1) false trail. Upgrade the mraa library (the BBG  came with v 0.95) to version 1.5.x. this was pretty tough for an absolute beginner like me. Needed swig3.0, which can be installed using debians dpkg. Need Cmake which was somewhat difficult to get an image of with out having an sd card. it took some time to get it installed. mraa installs files in sys/local/lib vs sys/lib like cloud9 expects to see. Once mrraa was installed, i had to correct ly place a few files to get it to work, but mraa 1.5 would fail to initalize pwm on the pins, I dont know why as using mraa commands to check the pins always returned correct values, but it still failed.

2) current state.  I bought a micro SD card and installed the latest BBG image on the eprom. This came with mraa1.0.  Still all the BBIO python examples are junk. You no longer get a buffer overrun using mraa.write(), but you can still lock up the pwm.

End entry 4



On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Greg

unread,
Nov 13, 2016, 6:40:59 PM11/13/16
to BeagleBoard
The bonescript stuff is cool and the way it works with the webserver is fascinating.
It's possible you may hit a few limitations quickly.  I think you might already be there.

So next, get Derek Molloy's outstanding book "Exploring Beaglebone".
Start reading and trying the examples in this book.

A first order of business is to flash a micro-sd card with one of the latest Debian images.
Don't use a "flasher image".  The flasher image will write itself to the flash memory on the board.
You can leave that intact for now and get work done on the microsd.  If it gets trashed it will not be a disaster.
Later on, when you start working on a serious project, you can create a git based project and push it to a local
or remote server for backup.

Great choice on the Green, best one to start with.  Enjoy the adventure!

Regards,
Greg

Chris M

unread,
Nov 13, 2016, 6:43:55 PM11/13/16
to BeagleBoard

evilwulfie

unread,
Nov 13, 2016, 6:46:15 PM11/13/16
to beagl...@googlegroups.com
doing real time things in userland dont work well.

Using the PWM is the best way to step motors
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/6611fa64-374e-48ae-b64b-5b41d749592e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Greg

unread,
Nov 13, 2016, 7:08:55 PM11/13/16
to BeagleBoard
http://exploringbeaglebone.com/

Note the "Chapters" in the upper right.  There is a huge amount of info here!

Robert Nelson

unread,
Nov 13, 2016, 7:12:11 PM11/13/16
to Beagle Board

On Nov 13, 2016 4:25 PM, "Chris M" <chron...@gmail.com> wrote:
>
> 1) The first tutorial blinking the four onboard leds.
>
> I did the tutorial using bonescript and also by using echo > at the prompt to change the corresponding files ( /sys/class/leds/beaglebone\:green\:usrx)
>  
> ISSUE FOUND:
> One thing I wrestled with was the leds by default do not follow the predescribed operational pattern.  Echoing "none" to the trigger files and other changes to the bonescript did not have any affect.
> The leds would continue to alternate 1,3 lit then 2,4 lit.   It was obvious that something else was writing to the leds and was interfering with the tutorials.

On the BBGW, this is the signal that wifi isn't connected to an AP. This was a choice made by Seeed for their out of box experience.

Regards,

Chris M

unread,
Nov 13, 2016, 7:29:40 PM11/13/16
to BeagleBoard
6) PWM experiments

I wrote three python scripts to run pwm on mraa pin 62 (P9-16). Remembering the mraa library is now v1.0 and not 1.5.

period range max <1 sec. min 1us (using _us)
when using .write() to set the duty cycle results in some screwy things happening and locking up of the pwm chip. I quickly decided it is best to us .pulsewidth() to directly set the value.
pulsewidth(), pulsewidth_ms() minimum value cannot be less than 1ms (.001sec)  the max cannot be more than the period.

I had the best luck with "_us" range, and did not experience pulse width related hardware/ software crashes.

I could get the pwm chip to generate signals from 1us period to 1x10^6 us period, that i could see on my scope.

import mraa
print (mraa.getVersion())
# set up pins to run stepper motor pulse & direction
pin = mraa.Pwm(62)
pindir = mraa.Gpio(59)
#set initial direction of motor, 1st tell pin that it is to send a signal (dir), then write value (0 or 1)
pindir.dir(mraa.DIR_OUT)
pindir.write(0)
# variable to set frequency and pulse width for testing
period = 100
#enable the pwm pin
pin.enable(True)
# initialize the pin
pin.period_us(period)
#set the pulsewidth to 25% of the period
pin.pulsewidth_us(int(period/4))
#program loop it is not necessary to write to the pin every loop
while period <> 0:
    period = input("integer(us)number /0 to quit: ")
    pin.pulsewidth_us(0)
    pin.period_us(period)
    pin.pulsewidth_us(int(period/4))
# a bit of clean up   
pin.enable(False)


   On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 13, 2016, 8:31:23 PM11/13/16
to BeagleBoard


Period 1 us



On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 15, 2016, 11:15:15 PM11/15/16
to BeagleBoard
7)Setting up a link sprite LS-Y201 camera I bought.

It took some time to get the UART pins to work on the BBG. 

ISSUE FOUND:
The UART pins are not enabled by default as UART pins. I tried several methods, and ended up following the instructions posted here (http://tinkernow.com/2015/01/beaglebone-black-rs232-uart-setup/) to set up and test the pins.

SOLUTION:
Changing adding the pins to the /boot/uEnv.txt file allowed  the minicom test to work.
You cannot install minicom with apt get / dpkg until you update the package library (apt-get update) at the root dir



end entry 7




Auto Generated Inline Image 1

Chris M

unread,
Nov 15, 2016, 11:49:36 PM11/15/16
to BeagleBoard
8) Setting up a link sprite LS-Y201 camera continued.

Some searching on the internet lead me to this site( http://bradsmc.blogspot.com/2013/05/taking-larger-pictures-with-pcduino.html).

I used his work to create two python programs 1st to take pictures and the 2nd to change the picture sizes. (Ill post them sepaerately)

ISSUES
LINKSPRITE CAMERA changing the baud rate not very intuitive. soem time the change is persistent othertime not.

SOLUTION
Always set the baud to default on exit.





On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 15, 2016, 11:58:25 PM11/15/16
to BeagleBoard


import sys
import serial
import time
import datetime

# Initialize camera (LINKSPRITE LS-Y201 JPG w/ IR)
ser = serial.Serial(port = "/dev/ttyO1", baudrate=38400)
#Rest the camera (HEX 56 00 26 00)
ser.write(b'\x56\0\x26\0')
resp = ""
#DELAY TO ALLOW camera to fill response buffer
time.sleep(0.5)
#Read the Response from the camera and check for String
resp=""
while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if "Init end\r\n" in resp:
        print "Camera Reset"

# Set Baud Rate
# 115200
ser.write(b'\x56\x00\x24\x03\x01\x0D\xA6')
# 57600
#ser.write(b'\x56\0\x24\x03\x01\x1C\x4C')
# 38400
#ser.write(b'\x56\x00\x24\x03\x01\x2A\xF2')
# 19200
#ser.write(b'\x56\x00\x24\x03\x01\x56\xE4')
#DELAY TO ALLOW camera to fill response buffer

time.sleep(.01)
#change UART PIN baudrate to match camera
ser.baudrate = 115200
#Read the Response from the camera and check for String
resp = ""
while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if b'\x76\0\x24\0\0' in resp:
        print "Baudrate changed"

# Take picture
# Command (HEX 56 00 36 01 00)

ser.write(b'\x56\0\x36\x01\0')
#DELAY TO ALLOW camera to fill response buffer
time.sleep(.01)
#Read the Response from the camera and check for String
resp = ""
while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if b'\x76\0\x36\0\0' in resp:
        print "Picture taken"

#Get JPG size
# Command  (HEX 56 00 34 01 00)

ser.write(b'\x56\0\x34\x01\0')
#DELAY TO ALLOW camera to fill response buffer
time.sleep(.01)
#Read the Response from the camera and check for String
resp = ""
while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if b'\x76\0\x34\0\x04\0\0' in resp:
        # if correct return string is read the next two reads will be size
        msb = ser.read()
        lsb = ser.read()
        print "Image file size: %d bytes" % (ord(msb) << 8 | ord(lsb))

# Write image to file
# Command to Read jpeg data (HEX 56 00 32 0C 00 0A 00 00 00 00 KH KL 00 0A)

ser.write(b'\x56\0\x32\x0C\0\x0A\0\0\0\0\0\0%c%c\0\x0A' % (msb,lsb))
# DELAY to allow camera to fill buffer with picture data bigger files need more time
time.sleep(.01)
# Create a unique file name and save it to where you can get it from cloud9 ide
now = datetime.datetime.now()
filename = "%d.%02d.%02d.%02d.%02d.%02d.jpg" % \
(now.year,now.month,now.day,now.hour,now.minute,now.second)
resp = ser.read(size=5)
if b'\x76\0\x32\0\0' in resp:
    with open("/var/lib/cloud9/pictures/" + filename, 'wb') as f:
        while (ser.inWaiting() > 0):
            data = ser.read()
            f.write('%c' % data)
    print "Image written to /tmp/%s" % (filename)

# reset the Baudrate to default 38400 and close the serial port
ser.write(b'\x56\x00\x24\x03\x01\x2A\xF2')
ser.close()


Auto Generated Inline Image 1

Chris M

unread,
Nov 16, 2016, 12:01:30 AM11/16/16
to BeagleBoard








changing the picture size


import sys
import serial
import time

# Initialize camera (LINKSPRITE LS-Y201 JPG w/ IR)
ser = serial.Serial(port = "/dev/ttyO1", baudrate=38400)
#Rest the camera (HEX 56 00 26 00)
ser.write(b'\x56\0\x26\0')
resp = ""
#DELAY TO ALLOW camera to fill response buffer
time.sleep(0.5)
#Read the Response from the camera and check for String
resp=""
while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if "Init end\r\n" in resp:
        print "Camera Reset"

#change size
# The camera must be reset or have the power cycled for this to take affect
# Probably should be a separate program, only run one time,
#640x480
#ser.write(b'\x56\0\x31\x05\x04\x01\0\x19\0')

#320x240
ser.write(b'\x56\0\x31\x05\x04\x01\0\x19\x11')
#160x120
#ser.write(b'\x56\0\x31\x05\x04\x01\0\x19\x22')

time.sleep(.5)

while (ser.inWaiting() > 0):
    data = ser.read()
    resp += data
    if b'\x76\0\x31\0\0' in resp:
        print "Size changed must cycle camera power or reset"
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Chris M

unread,
Nov 16, 2016, 12:07:13 AM11/16/16
to BeagleBoard

Chris M

unread,
Nov 22, 2016, 10:09:28 PM11/22/16
to BeagleBoard
9) things to install and update after image is installed.

Mount an external sd card for extra storage.

# df -h
tells you what is  mounted

# fdisk -l | grep '^Disk'
Disk /dev/mmcblk1: 3.7 GiB, 3909091328 bytes, 7634944 sectors
Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
tells you all the storage devices

manage partitions
# fdisk /dev/mmcblk0

format partition (
mmcblk0p1)can change depending on situation

# mkfs.ext3 /dev/
mmcblk0p1

mount the disk at a new folder
# mkdir /extsd
# mount /dev/
mmcblk0p1 /extsd

update apt-get
# apt-get update

install cmake again




Chris M

unread,
Nov 22, 2016, 10:29:12 PM11/22/16
to BeagleBoard

spent the weekend trying to get a usb web cam to work with python
there are many false trails on the internet. ended up following

http://www.chioka.in/python-live-video-streaming-example/
https://github.com/log0/video_streaming_with_flask_example
and
https://blog.miguelgrinberg.com/post/video-streaming-with-flask

installed pythons opencv

took some time to get things too work.
 time out error was solved by
http://stackoverflow.com/questions/27769561/opencv-python-cv2-videocapture0-grab-and-cv2-videocapture0-read-hangs

using mjpeg compression relies on the BBB to decode (tobyte() command is really tostring() command. making live streaming very slow and laggy.

began to explore opencv with neon per

http://blog.lemoneerlabs.com/3rdParty/Darling_BBB_30fps_DRAFT.html
and
http://vuanhtung.blogspot.com/2014/04/and-updated-guide-to-get-hardware.html

after installing opencv per their instructions i kept getting a file too small error when importing cv2
decide try to reinstall debian image and start over.








On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 22, 2016, 10:37:04 PM11/22/16
to BeagleBoard

Chris M

unread,
Nov 22, 2016, 11:08:20 PM11/22/16
to BeagleBoard
mount them.

Field definitions

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

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

  • <dir> - tells the mount command where it should mount the <file system> to.

  • <type> - 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.

  • <options> - 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,


Chris M

unread,
Nov 23, 2016, 1:04:18 AM11/23/16
to BeagleBoard
10) installing flask/ flaskio, etc.

pip install ....


On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 24, 2016, 1:10:32 PM11/24/16
to BeagleBoard
9) 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()



On Sunday, November 13, 2016 at 4:09:06 PM UTC-6, Chris M wrote:

Chris M

unread,
Nov 24, 2016, 1:52:04 PM11/24/16
to BeagleBoard
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

Chris M

unread,
Nov 25, 2016, 10:38:47 AM11/25/16
to BeagleBoard

Chris M

unread,
Nov 26, 2016, 12:30:12 AM11/26/16
to BeagleBoard

RobertCNelson
6/12/14
On Thu, Jun 12, 2014 at 8:16 AM,  <cla...@logmatch.com.br> wrote:
> 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 -
Auto Generated Inline Image 1

Chris M

unread,
Nov 27, 2016, 9:15:24 PM11/27/16
to BeagleBoard
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

Chris M

unread,
Nov 27, 2016, 10:14:23 PM11/27/16
to BeagleBoard
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


Chris M

unread,
Nov 29, 2016, 10:23:30 PM11/29/16
to BeagleBoard
                     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


Chris M

unread,
Nov 30, 2016, 9:52:54 PM11/30/16
to BeagleBoard
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)
 

Chris M

unread,
Dec 10, 2016, 11:28:31 AM12/10/16
to BeagleBoard
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)
Message has been deleted

Chris M

unread,
Jan 4, 2017, 9:33:10 PM1/4/17
to BeagleBoard

me (Chris M change)

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 https://github.com/gebart/python-v4l2capture
python-v4l2capture uses distutils.
To build: ./setup.py build
To build and install: ./setup.py install

pip install pillow

Auto Generated Inline Image 1
Message has been deleted
Message has been deleted
Message has been deleted

Chris M

unread,
Oct 8, 2017, 9:51:16 PM10/8/17
to BeagleBoard
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

2) 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

Chris M

unread,
Oct 11, 2017, 12:11:30 AM10/11/17
to BeagleBoard

 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

2) 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
5) 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.

 
Reply all
Reply to author
Forward
0 new messages