Month: January 2018

A huddle of electronic modules

I decided to list all the modules on my pile of modules:

3 – Relay module
2 – Analog Microphone module with ampliflier
2 – ADXL345 Accelerometer module (GY-291)
2 – Zero cross detector module
3 – GP2Y0AH01K0F distance sensor
4 – LDR sensor module
1 – MPU9250 module
3 – 4×4 telephone keypad module
2 – PS2 joystick module
1 – VEML6070 UV sensor module
1 – W25Q32FVZPIG SPI NOR Flash module
1 – VS1053 Audio MP3 module
8 – nRF24 2.4GHz module
5 – MicroSD Card module
1 – WS2812 Breakout module
1 – OV7660 (CF7670C-V2) camera module
2 – HMC5883L 3-axis compass (GY-273)
2 – HMC5983 3-axis compass module (GY-282)
2 – Si1145 UV IR light sensor module (GY1145)
1 – BMP280 pressure module
3 – MAX485 RS485 module from LC Technology
1 – ML8511 Analog UV sensor module (GYML8511)
2 – ACS712 Current sensor module
2 – Hall sensor analog module with amplifier
1 – Tilt module (mercury bulb)
1 – Tilt module with 2 brass capsule/tube
2 – GY-86 10DOF MS5611 HMC5883L MPU6050 module (GY-86)
2 – LM75 temperature sensor module (CJMCU-75)
2 – APDS-9960 Gesture sensor module
1 – RDA5807M FM module (RRD-102)
1 – SX1509 keypad controller module
3 – Laser pointer module
3 – Reed-switch module with amplifier
2 – MQ2 butane sensor module (FC-22)
1 – Hall sensor module without amplifier (Keyes without number)
2 – MCP4725 DAC module
2 – ADCL335 Analog Accelerometer module (GY-61)
2 – Ra-01 LoRa module 433MHz
1 – TCS34725FN Color Light sensor module
1 – BH1750FVI light sensor module
1 – MAX30100 Pulse Oximeter and Heart-Rate Sensor module
2 – Buzzer module (RobotDyn)
1 – LSM6DS3 3-axis accelometer gyroscope
1 – MLX90614 Infrared Thermometer module (GY-906)
2 – BME-280 pressure module
1 – VL53L0X laser ranging sensor module (GYVL53L0X)
5 – TXB0108 level-shifter module (HW-0108)
1 – HTU21 humidity sensor module (GY-21)
2 – TEA5767 FM radio module (PL102BC-N)
1 – DHT11 humidity and temperature sensor module
2 – Thyristor AC switch 5V logic AC 220V/5A module
1 – DS18B20 1-wire temperature probe
1 – USB Audio IN/OUT module
1 – AT24C02B EEPROM module
5 – HX711 24-bit ADC Load Cell amplifier module
1 – BMP180 barometer sensor module (GY-68)
2 – ??? module with a small QFN chip with this code: 2222 C3H 9L8GS
5 – mini joysticks 5-way
3 – slide potentiometer
3 – photodetectors similar used on mouse
1 – voltage regulator module LM2596 DC-DC
1 – RTC module DS1302
1 – SIM800 modem module
3 – MAX6675 thermocoupler module
1 – SI4703 FM Radio Module
1 – CDM324 Radar Module
1 – ILI9486 LCD Module
3 – SN65HVD230 CAN Transceiver

I already created drivers for some of these sensors in the NuttX (i.e.: ADXL345, APDS-9960, BH1750FVI, BMP180, VEML6070, ZeroCross, etc). But there are many more to be added.

How to build NuttX on Windows 10

First let me to make things clear: I stopped using Windows operating system about 18 years ago, when in 2000 Chernobyl virus erased the BIOS Flash and the Hard Disk of my computer that was running Windows 98 at that time.

But since many people are asking me to show how to compile NuttX on Windows, I will show how you can do it using Windows 10 (sorry Windows 7, Windows Vista, Windows XP, Windows 2000, Windows Millennium, Windows 98, Windows 95, Windows 3.1, … and DOS users, but it only works on Windows 10).

You need to enable to “Developer Mode” of Windows: click on Window icon at bottom left corner of your screen and then click on “Windows Settings” (gear icon).

Settings:

In the “Windows Settings” click on “Update & Security”.

Update & Security:

Inside it click in “For Developers”.

For developers:

And enable the option “Developer Mode”.

Developer mode:

After that you need to enable the Windows Subsystem for Linux. Open the “Control Panel”.

Control Panel:

Enter inside “Programs”.

Programs:

Click on “Turn Windows features on or off”.

Turn Windows features on or off:

Then it will open the “Windows Features” window, scroll down until you find “Windows Subsystem for Linux”.

Enable the Windows Subsystem for Linux:

Then click to enable it:

At this moment the Windows will ask to restart, click in the Restart button.

When the system restarted you can run the “bash” command:

It will show the message explaining the a Linux distribution is not installed:

Open the browser and go to: https://aka.ms/wslstore

The the Microsoft Store will open automatically:

Click in the Ubuntu distribution, and the click on Get button:

When it finishes the download click on Launch button:

It will run the installation script, when it finishes you can close it and run the Ubuntu command:

Then the Linux terminal will open:

Now you can follow these steps to compile NuttX:

$ sudo apt-get update

$ sudo apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf git libncurses5-dev libtool libusb-dev libusb-1.0.0-dev pkg-config

Create the nuttx workspace:

mkdir ~/nuttxspace

cd ~/nuttxspace

The Windows Subsystem for Linux doesn’t support USB devices (except USB Pendrive), then we don’t need to install OpenOCD. We will use the JLink too on Windows itself.

Clone the NuttX repositories:

$ cd ~/nuttxspace

$ git clone https://bitbucket.org/nuttx/nuttx

$ git clone https://bitbucket.org/nuttx/apps

$ git clone https://bitbucket.org/nuttx/tools

Configure, compile and install the Kconfig-Frontends (needed by NuttX’s menuconfig)

$ cd ~/nuttxspace

$ cd tools/kconfig-frontends/

$ ./configure

$ make

$ sudo make install

$ sudo ldconfig

Now we can compile NuttX for XMC4-Relax board!

Run the configure script:

$ cd ~/nuttxspace

$ cd nuttx

$ ./tools/configure.sh xmc4500-relax/nsh

Run menuconfig and change the build to Linux and UART3 as serial console:

$ make menuconfig

Build Setup  --->
    Build Host Platform (Linux)

System Type  --->
    XMC4xxx Peripheral Support  --->
        [ ] USIC0
        [*] USIC1  (press SPACE to select)
        [ ] USIC2

    XMC4xxx USIC Configuration  --->
        USIC1 Channel 0 Configuration (Not used)  --->
        USIC1 Channel 1 Configuration (UART3)  --->

Device Drivers  --->
    [*] Serial Driver Support  --->
        Serial console (UART3)  --->

Time to compile it:

$ make

If everything compiled correctly you get a nuttx.bin:

$ ls -l nuttx.bin
-rwxrwxr-x 1 alan alan 79804 Jan  8 12:25 nuttx.bin

Just copy this nuttx.bin binary to Windows side:

$ cp nuttx.bin /mnt/c/ProgramData/

You will need to configure Windows Explorer to show Hidden files, this way you could see the nuttx.bin at C:\ProgramData

Running NuttX on Infineon XMC4500-Relax

This is a step-by-step tutorial explaining how to compile and install NuttX on Infineon XMC4500-Relax board.

These steps where tested on Ubuntu 16.04 LTS (Long Term Support).

Open the Linux terminal and install the dependence packages using this command:

$ sudo apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf git libncurses5-dev libtool libusb-dev libusb-1.0.0-dev pkg-config

Create the nuttx workspace:

mkdir ~/nuttxspace

cd ~/nuttxspace

Clone and compile the OpenOCD (it is used to flash the firmware in the board).

$ git clone http://repo.or.cz/r/openocd.git

$ cd ~/nuttxspace/openocd

$ ./bootstrap

$ ./configure --enable-internal-jimtcl --enable-maintainer-mode --disable-werror --disable-shared --enable-stlink --enable-jlink --enable-rlink --enable-vslink --enable-ti-icdi --enable-remote-bitbang

$ make

$ sudo make install

Copy the OpenOCD udev rules and update it:

$ cd contrib

$ sudo cp 60-openocd.rules /etc/udev/rules.d/

$ sudo udevadm trigger

Clone the NuttX repositories:

$ cd ~/nuttxspace

$ git clone https://bitbucket.org/nuttx/nuttx

$ git clone https://bitbucket.org/nuttx/apps

$ git clone https://bitbucket.org/nuttx/tools

Configure, compile and install the Kconfig-Frontends (needed by NuttX’s menuconfig)

$ cd ~/nuttxspace

$ cd tools/kconfig-frontends/

$ ./configure

$ make

$ sudo make install

$ sudo ldconfig

Now we can compile NuttX for XMC4-Relax board!

Run the configure script:

$ cd ~/nuttxspace

$ cd nuttx

$ ./tools/configure.sh xmc4500-relax/nsh

Run menuconfig and change the build to Linux and UART3 as serial console:

$ make menuconfig

Build Setup  --->
    Build Host Platform (Linux)

System Type  --->
    XMC4xxx Peripheral Support  --->
        [ ] USIC0
        [*] USIC1  (press SPACE to select)
        [ ] USIC2

    XMC4xxx USIC Configuration  --->
        USIC1 Channel 0 Configuration (Not used)  --->
        USIC1 Channel 1 Configuration (UART3)  --->

Device Drivers  --->
    [*] Serial Driver Support  --->
        Serial console (UART3)  --->

Time to compile it:

$ make

If everything compiled correctly you get a nuttx.bin:

$ ls -l nuttx.bin
-rwxrwxr-x 1 alan alan 79804 Jan  8 12:25 nuttx.bin

Plug the USB cable on you computer and on XMC4500-Relax board and use OpenOCD to flash it:

$ sudo openocd -f board/xmc4500-relax.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x0c000000"

You should see these messages:

$ sudo openocd -f board/xmc4500-relax.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x0c000000"
Open On-Chip Debugger 0.10.0+dev-00172-g7719e96 (2017-11-12-09:13)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 4000 kHz
cortex_m reset_config sysresetreq
adapter speed: 1000 kHz
Info : No device selected, using first device.
Info : J-Link Lite-XMC4000 Rev.1 compiled Apr  2 2015 18:25:20
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : xmc4500.cpu: hardware has 6 breakpoints, 4 watchpoints
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000200 msp: 0x20001e84
auto erase enabled
Info : Clearing flash status
Info : Clearing flash status
wrote 81920 bytes from file nuttx.bin in 19.998228s (4.000 KiB/s)

Configure your Linux machine to let your user to have access to serial port:

$ sudo usermod -a -G dialout alan

You just replace ‘alan’ with your username.

You need a USB/Serial adapter that works to 3.3V, like FDTI dongle or Silabs CP2102.

Connect the USB/Serial RXD to XMC4500-Relax board P0.1 (Header pin X1 pin 34), connect TXD to P0.0 (Header pin X1 pin 36) and connect the GND to board GND (Header pin X1 pin 1, 2, 3 or 4).

Configure minicom to use your USB/Serial adapter (i.e. at /dev/ttyUSB0) to 115200 8n1:

$ sudo minicom -s

Serial port setup
    A -    Serial Device      : /dev/ttyUSB0
    E -    Bps/Par/Bits       : 115200 8N1
    F - Hardware Flow Control : No
    G - Software Flow Control : No

Save setup as dfl

Exit

Press the XMC4500 Reset button and you should see:

NuttShell (NSH)                                                                 
nsh>

Type ‘help’ or ‘?’ to the the listing of enabled commands:

nsh> help
help usage:  help [-v] []

  [           dirname     help        mh          set         unset       
  ?           dd          hexdump     mount       sh          usleep      
  basename    df          kill        mv          sleep       xd          
  break       echo        ls          mw          test        
  cat         exec        mb          ps          time        
  cd          exit        mkdir       pwd         true        
  cp          false       mkfatfs     rm          uname       
  cmp         free        mkrd        rmdir       umount      

Builtin Apps:
  i2c
  ramtest
nsh> 

Running NuttX on ESP32 board

NuttX supports the Expressif ESP32 inclusive with SMP (Symmetric MultiProcessing) support, then I decided to post here the steps I followed to get it working:

Install esptool:

$ sudo pip install esptool

Install to toolchain:

You can download the pre-build toolchain:

https://esp-idf.readthedocs.io/en/latest/get-started/index.html

Or: you can compile it from source code:

$ git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
$ cd crosstool-NG
$ ./bootstrap && ./configure --prefix=$PWD && make install
$ ./ct-ng xtensa-esp32-elf
$ unset LD_LIBRARY_PATH
$ ./ct-ng build
$ chmod -R u+w builds/xtensa-esp32-elf
$ sudo cp -a builds/xtensa-esp32-elf/* /usr/local/

Now you can compile the NuttX:

$ mkdir ~/nuttxspace
$ cd ~/nuttxspace
$ git clone https://bitbucket.org/nuttx/nuttx
$ git clone https://bitbucket.org/nuttx/apps
$ cd nuttx
$ make distclean
$ ./tools/configure.sh esp32-core/nsh
$ make

The nuttx.bin generated is too big, you need to generate it from elf file (nuttx) :

$ esptool.py --chip esp32 elf2image --flash_mode dio --flash_size 4MB -o ./nuttx.bin nuttx

You will need the bootloader.bin and the partitions, you can get it from hello word example. You need to clone and update the submodules of esp-idf (read the Get Started from above link), then:

$ cp -a esp-idf/examples/get-started/hello_world .
$ cd hello_world
$ make
$ cp build/bootloader/bootloader.bin ~/nuttxspace/nuttx/
$ cp build/partitions_singleapp.bin ~/nuttxspace/nuttx/partitions.bin

The files nuttx.bin, bootloader.bin and partitions.bin need to be flashed in the board. To do that first put the board in ROM Boot mode:

Press and hold the BOOT button of ESP32 board (IO0 pin will be put in low level) and press and release the RESET button. Now you can release the BOOT button.

This is the command to flash:

$ sudo esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 write_flash 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 nuttx.bin
esptool.py v2.2
Connecting....
Chip is ESP32D0WDQ6 (revision 0)
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 19392 bytes to 11445...
Wrote 19392 bytes (11445 compressed) at 0x00001000 in 0.2 seconds (effective 901.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 82...
Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 10507.6 kbit/s)...
Hash of data verified.
Compressed 185024 bytes to 45527...
Wrote 185024 bytes (45527 compressed) at 0x00010000 in 2.1 seconds (effective 710.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...
$

Finally open minicom and just reset the board, you should get it:

$ minicom


Welcome to minicom 2.7

OPTIONS: I18n 
Compiled on Feb  7 2016, 13:37:27.
Port /dev/ttyUSB0, 15:40:48

Press CTRL-A Z for help on special keys

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5568
ho 0 tail 12 room 4
load:0x40078000,len:0
load:0x40078000,len:13716
entry 0x40078fb4
I (31) boot: ESP-IDF v3.1-dev-162-geb659e4 2nd stage bootloader
I (31) boot: compile time 15:35:11
I (42) boot: Enabling RNG early entropy source...
I (42) boot: SPI Speed      : 40MHz
I (42) boot: SPI Mode       : DIO
I (45) boot: SPI Flash Size : 4MB
I (49) boot: Partition Table:
I (52) boot: ## Label            Usage          Type ST Offset   Length
I (60) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (67) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (75) boot:  2 factory          factory app      00 00 00010000 00100000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=0x00010020 vaddr=0x3ffb0df0 size=0x00054 (    84) load
I (95) esp_image: segment 1: paddr=0x0001007c vaddr=0x40080000 size=0x00400 (  1024) load
I (104) esp_image: segment 2: paddr=0x00010484 vaddr=0x40080400 size=0x00300 (   768) load
I (113) esp_image: segment 3: paddr=0x0001078c vaddr=0x400c0000 size=0x00000 (     0) load
I (122) esp_image: segment 4: paddr=0x00010794 vaddr=0x00000000 size=0x0f874 ( 63604) 
I (153) esp_image: segment 5: paddr=0x00020010 vaddr=0x3f400010 size=0x018e4 (  6372) map
I (155) esp_image: segment 6: paddr=0x000218fc vaddr=0x00000000 size=0x0e714 ( 59156) 
I (179) esp_image: segment 7: paddr=0x00030018 vaddr=0x400d0018 size=0x0d278 ( 53880) map
I (199) boot: Loaded app from partition at offset 0x10000
I (199) boot: Disabling RNG early entropy source...

NuttShell (NSH)
nsh> 
nsh> ?
help usage:  help [-v] []

  [           cmp         false       mkdir       rm          true        
  ?           dirname     free        mh          rmdir       uname       
  basename    dd          help        mount       set         umount      
  break       df          hexdump     mv          sh          unset       
  cat         echo        kill        mw          sleep       usleep      
  cd          exec        ls          ps          test        xd          
  cp          exit        mb          pwd         time        

Builtin Apps:
nsh>

How to get IRC notification on pidgin

I use pidgin as my centralized message application (Google Hangout, Jabber, ICQ, …) and also to get messages from freenode IRC.

But there is an issue with #IRC support on pidgin: I don’t know when someone posted a new message in the channel (#nuttx channel of course).

Then search about it a found a solution here:

https://ubuntuforums.org/showthread.php?t=1415173

There is a program called pidgin-irc-notifications that helps:

https://bitbucket.org/boralyl/pidgin-irc-notifications/overview

Note: I need to install pynotify first:

$ sudo pip install py-notify