• Experiences with an MH-Z19 CO2 sensor

    09/30/2016 at 09:58 3 comments

    My experiences with the MH-Z19 NDIR CO2 sensor

    Warning: I just destroyed my MH-Z19 sensor when soldering, I was changing connectors with lead free solder, iron set to 380 C. I had to heat for a little while to remove the old header. Now the sensor only gives a very low value, both on PWM and serial output.

    Before destroying the device, I was getting strange values around 900 ppm when I should have been getting around 400 ppm. PWM and serial values were consistent but wrong.

    My guess is that the firmware in the device for some reason thought it had a 2000 ppm range instead of 5000. Scaling the 900 ppm by 2000 / 5000 gives 360 ppm. I tried playing with the reserved "SR" pin (thinking it might mean "set range", but with no success.

    Maybe I'll open my sensor up to see how it works on the inside. In any case, I'll order another sensor.

  • nRF51822 development on the Mac

    03/11/2016 at 14:28 0 comments

    March 11, 2016

    It took a full day, but I now believe I have the the latest version (10) of Nordic's SDK working on my Mac.

    I mainly followed instructions here. Do read that page also, it has some tips, like running gdb, that I won't cover here.

    Some of the difficulties came from the fact that there are different versions of the ARM toolchain, SDK, SoftDevice and IC:s.

    I'm now using SDK 10 downloaded from here.

    I'm using the latest ARM toolchain, version 5.2.1, downloaded from here. Unpacked in /usr/local

    My IC is an nRF51822QFAAH0 (this is printed on the IC). H0 means it is a revision three chip. You might be interested in Nordic's Compatibility Matrix.

    I also installed the latest drivers from Segger for my J-Link programmer I originally got with a development kit from Nordic.

    In the SDK, I modified components/toolchain/gcc/Makefile.posix to be:

    GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-5_2-2015q4
    
    GNU_VERSION := 5.1.2
    
    GNU_PREFIX := arm-none-eabi
    

    I did my testing with the HRS (Heart Rate Service) example code.

    Do:

    cd examples/ble_peripheral/ble_app_hrs/pca10028/s110/armgcc

    The problem here was all examples are preconfigured for the nRF51422 chip, whereas I have the 51822.

    Copy the right linker script to this directory (I had a lot of grief before I figured this one out), in my case:

    cp <sdk root>/components/softdevice/s110/toolchain/armgcc/armgcc_s110_nrf51822_xxaa.ld .
    

    I then added the nrf51822_xxaa as a target in the Makefile. Around line 168 of the makefile, I duplicated the lines for the nrf51422_xxac_s110 target, renamed them to nrf51822_xxaa_s110, changed the output filename and linker script thusly:

    OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
    
    nrf51422_xxac_s110: OUTPUT_FILENAME := nrf51422_xxac_s110
    
    nrf51422_xxac_s110: LINKER_SCRIPT=ble_app_hrs_gcc_nrf51.ld
    
    nrf51422_xxac_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
    
    @echo Linking target: $(OUTPUT_FILENAME).out
    
            $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    
            $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
    
    nrf51822_xxaa_s110: OUTPUT_FILENAME := nrf51822_xxaa_s110
    
    nrf51822_xxaa_s110: LINKER_SCRIPT= armgcc_s110_nrf51822_xxaa.ld
    
    nrf51822_xxaa_s110: $(BUILD_DIRECTORIES) $(OBJECTS)
    
    @echo Linking target: $(OUTPUT_FILENAME).out
    
            $(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
    
            $(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
    
    

    I could then build the code with:

    $ make nrf51822_xxaa_s110
    To program the chip, use JLinkExe to erase the flash (the magic w4 commands they have turned out to be neccessary when changing softDevice), flash the SoftDevice and the application, then reset the device. Once you have the SoftDevice in place, you only need to flash the application.

    $ JLinkExe -device nrf51822_xxaa -if swd -speed 4000
    SEGGER J-Link Commander V5.10s (Compiled Mar  9 2016 18:54:51)
    
    DLL version V5.10s, compiled Mar  9 2016 18:54:45
    
    Connecting to J-Link via USB...O.K.
    
    Firmware: J-Link Lite-Cortex-M V8 compiled Aug 20 2015 17:57:19
    
    Hardware version: V8.00
    
    S/N: 518002428
    
    License(s): GDB
    
    Emulator has Trace capability
    
    VTref = 3.287V
    
    Type "connect" to establish a target connection, '?' for help
    
    J-Link>connect
    
    Device "NRF51822_XXAA" selected.
    
    Found SWD-DP with ID 0x0BB11477
    
    Found Cortex-M0 r0p0, Little endian.
    
    FPUnit: 4 code (BP) slots and 0 literal slots
    
    CoreSight components:
    
    ROMTbl 0 @ F0000000
    
    ROMTbl 0 [0]: F00FF000, CID: B105100D, PID: 000BB471 ROM Table
    
    ROMTbl 1 @ E00FF000
    
    ROMTbl 1 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
    
    ROMTbl 1 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
    
    ROMTbl 1 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
    
    ROMTbl 0 [1]: 00002000, CID: B105900D, PID: 000BB9A3 ???
    
    Cortex-M0 identified.
    
    J-Link>w4 4001e504 2
    
    Writing 00000002 -> 4001E504
    
    J-Link>w4 4001e50c 1
    
    Writing 00000001 -> 4001E50C
    
    J-Link>loadbin ../../../../../../components/softdevice/s110/hex/s110_nrf51_8.0.0_softdevice.hex 0
    
    Downloading file...
    Read more »