Tuesday, 27 November 2018

Tinkering GStreamer (0) : See myself from PC Camera


$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! ximagesink
Looks pretty clear: source is /dev/video0

ref:
https://github.com/umlaeute/v4l2loopback/issues/174
https://stackoverflow.com/questions/23354041/gstreamer-video-stream-error-and-breaks-dev-video-source

Saturday, 17 November 2018

Develop Micropython Firmware -- 01: Pure Python Based Driver

Micropython is almost like a mini operating system on a MCU and I'd like to build my own project standing on its shoulder.

Step 1: Setting up the environment
Just follow:
or

The awesome thing is that all the environment is in a virtual machine. Your host is safe. So finish configure the vagrant virtual box first and then compile ESP-toochain and Micropython source code in it.

pitfall 1: 
Depending on what kind of error you might run into, the following commands might help:

- vagrant box update
- vagrant box add ubuntu/trusty32 https://atlas.hashicorp.com/ubuntu/boxes/
vagrant provision

Step 2: coding the hello driver
Going into ~/micropython/drivers/, I found there are modules with C codes based and pure python based. In this tutorial, we focus on the pure python based drivers. For example, onewire and display.

step 2.1
mkdir hello_mpy

step 2.2
code hello_mpy.py:

def my_hello_mpy():
  print('This is my first micropython module.')

step 2.3
link it to esp8266 port.

cd ~/micropython/ports/esp8266/modules
ln -s ../../../drivers/hello_mpy/hello_mpy.py hello_mpy.py
ls -l
total 40
-rw-rw-r-- 1 vagrant vagrant  470 Nov 15 04:12 apa102.py
-rw-rw-r-- 1 vagrant vagrant  219 Nov 15 04:12 _boot.py
lrwxrwxrwx 1 vagrant vagrant   27 Nov 15 04:12 dht.py -> ../../../drivers/dht/dht.py
lrwxrwxrwx 1 vagrant vagrant   35 Nov 15 04:12 ds18x20.py -> ../../../drivers/onewire/ds18x20.py
-rw-rw-r-- 1 vagrant vagrant 1110 Nov 15 04:12 flashbdev.py
lrwxrwxrwx 1 vagrant vagrant   39 Nov 17 04:03 hello_mpy.py -> ../../../drivers/hello_mpy/hello_mpy.py
-rw-rw-r-- 1 vagrant vagrant 1425 Nov 15 04:12 inisetup.py
-rw-rw-r-- 1 vagrant vagrant  836 Nov 15 04:12 neopixel.py
-rw-rw-r-- 1 vagrant vagrant  850 Nov 15 04:12 ntptime.py
lrwxrwxrwx 1 vagrant vagrant   35 Nov 15 04:12 onewire.py -> ../../../drivers/onewire/onewire.py
-rw-rw-r-- 1 vagrant vagrant 1094 Nov 15 04:12 port_diag.py
lrwxrwxrwx 1 vagrant vagrant   22 Nov 15 04:12 upip.py -> ../../../tools/upip.py
lrwxrwxrwx 1 vagrant vagrant   31 Nov 15 04:12 upip_utarfile.py -> ../../../tools/upip_utarfile.py
-rw-rw-r-- 1 vagrant vagrant 2118 Nov 15 04:12 webrepl.py
-rw-rw-r-- 1 vagrant vagrant 2748 Nov 15 04:12 webrepl_setup.py
-rw-rw-r-- 1 vagrant vagrant 1624 Nov 15 04:12 websocket_helper.py

step 2.4 compile again
make axtls
make

step 2.5 
Get the .bin file out of vm.

pitfall 2:
I wasn't able to get my compiled firmware-combined.bin out from vm to host.
I eventually used vagrant-scp tool and it worked.
            https://github.com/invernizzi/vagrant-scp
It works both way, host to vm or vm to host.


Step 3: flash the new firmware
esptool.py -p /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 firmware-combined.bin

Step 4: use it
>>>import hello_mpy
>>>hello_mpy.my_hello_mpy()
This is my first micropython module.









Thursday, 15 November 2018

vagrant up issue

Ran in to problem when running:
$vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: aws_default_1449506528859_
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Specific bridge 'en0' not found. You may be asked to s
==> default: which network to bridge to.
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minut
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in th
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve
For example, if you're using VirtualBox, run vagrant up while the
VirtualBox GUI is open.
The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.
#######################################################
You simply need to turn on the virtualization setting in your BIOS.