bitknitting

~ Stuff I Learned About Tech+Hydroponics

bitknitting

Tag Archives: Ladybug Shield

On BLE, nobody knows if sensor readings are from an nRF51822 or an Arduino

14 Sunday Jun 2015

Posted by bitknitting in Uncategorized

≈ 2 Comments

Tags

I2C, Ladybug Shield, nRF51, nRF51822

In my previous post, I started exploring alternatives to the Arduino + Red Bear Lab BLE shields that are currently part of the Ladybug Shield design.  I’m noticing aggressive announcements by multiple vendors for SoCs that combine a micro controller like the Cortex m0 with BLE chips, many gpio ports, SPI, and I2C interfaces.  

I am using the nRF51 DK and Arm’s Keil v5 IDE.  In this post I take on the challenge of sending and receiving pH readings over i2c.  Once I can do that, I will have crossed the most major chasm between the digital and analog circuits of the Ladybug Shield. This will give me a clear idea if I could use the nRF51822 as a replacement for the Arduino + Red Bear Lab BLE shield.  I can’t wait to tell you…talk about a YIPPEE! moment….It works!!

The Goal

The goal of this post is to transmit data over the I2C interface.  Confirmation that the data was transferred will be output of the SDA/SCL lines when my Saleae Logic Analyzer is inserted between the I2C slave (I will be using Adafruit’s ADS1015 BoB…it could be any I2C chip at this point, I just needed a destination to transmit data to).

Thanks to Those That Went Before

Adafruit played a huge role in enabling me to get this to work.  Thank you  Adafruit for your open source availability, excellent tutorials, support, and products.    I hope/wish other companies embrace this ethos into their business model.  Imagine how many makers would be empowered on the nRF51822 if there were the same level of tutorial,  support, and product availability for Arm’s Keil IDE + nRF51822 BLE module.  

The first person I wanted to tell I got this working was Chris Gammell.  Chris has been a fantastic teacher and mentor.  I highly recommend his Contextual Electronics course – which I am currently a student.

Thank you Saleae for your EXCELLENT and reasonably priced logic analyzer.  I am a fan of your product and dedication to helping us easily/intuitively analyze our circuits.

The Test Setup

I used the same setup to simulate pH voltage (b) values as I did when I first started testing the pH circuit.  The other components in the test include Adafruit’s ADS1015 BoB (a) to provide the ADC conversion of the voltage into a digital value that is read from either an Arduino (c) or nRF51 (d) DK over i2c.

i2ctest_Arduino_nRF51DK

 

  • all shared the same ground
  • the voltage divider used a separate 5V power supply.
  • the Arduino or nRF52 DK used the USB power from my Mac.
  • I took advantage of the nRF52 DK’s mapping to the Arduino pin out, mapping SCL and SDA to the equivalent pins that are on the Arduino.  This way, I was less likely to mix up the green (SCL) and yellow (SDA) cables.
  • I used:
    • the Arduino’s 5V power source to power the ADS1015.
    • I used my DMM and logic analyzer to analyze results outside of the software.
    • I used Serial.println()s to analyze the results from the Arduino sketch.
    • I used the Keil debugger to step through and analyze results from the C source used on the nRF51 DK.

Results

The output of the voltage divider supplied the voltage reading to the ADS1015’s AIN0.  I used the default i2c address of the ADS1015 – 0x48.

Arduino

This image is a screen capture of the i2c traffic when the Arduino is used to get the ADC value:

LogicAnalyzerI2CnRF51. 

nRF51822

Here are the images for the i2c write and read traffic when the nRF51 DK is used:

Arduinoi2CWrite

i2c write traffic from the nRF51822 to the ADS1015

Arduinoi2CRead

i2c read traffic from the ADS1015 to the nRF51822

Traffic Analysis

(note: for the text below “master” could be either the Arduino or the nRF51 DK)

I found this tutorial on the I2C bus to be very helpful in understanding I2C traffic.  To read the traffic, we first have to know that read/write data transfers over i2c start with the master sending a byte in which the least significant bit (LSB) is either a 0 (for a write request from the master) or 1 (for a read request).  The higher 7 bits = the slave device’s address.  In the sniffs above, the first write traffic byte is 0x90 =  b1001 0000.  Thus the i2c address = b0100 1000 = 0x48 – the address of the ADS1015.  Since this is a write request, the least  the least significant bit is a 0.

The ADS1015 sees the traffic is for it so it sends back an ACK.  The write then occurs.  The master sense 0x01, which as noted in the ADS1010 data sheet“

Second byte: 0b00000001 (points to Config register)

Third byte: 0b00000100 (MSB of the Config register configuration)..in this example: 0xCE

Fourth byte: 0b10000011 (LSB of the Config register)….in this example: 0x83

While I could go on crafting packets based on the data sheet, the  Adafruit_ADS1X15 library makes writing code dramatically easier.   It provides a “cheat sheet” of the ADS1015 data sheet’s discussion of I2C packet formats.  The 0xC383 bytes are the result of a call to Adafruit’s readADC_SingleEnded() when m_gain = GAIN_ONE:

/**************************************************************************/

/*!

    @brief  Gets a single-ended ADC reading from the specified channel

*/

/**************************************************************************/

uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel) {

  if (channel > 3)

  {

    return 0;

  }

  

  // Start with default values

  uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)

                    ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)

                    ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)

                    ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)

                    ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)

                    ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)

 

  // Set PGA/voltage range

  config |= m_gain;

 

  // Set single-ended input channel

  switch (channel)

  {

    case (0):

      config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;

      break;

    case (1):

      config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;

      break;

    case (2):

      config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;

      break;

    case (3):

      config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;

      break;

  }

 

  // Set ‘start single-conversion’ bit

  config |= ADS1015_REG_CONFIG_OS_SINGLE;

 

  // Write config register to the ADC

  writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);

 

  // Wait for the conversion to complete

  delay(m_conversionDelay);

 

  // Read the conversion results

  // Shift 12-bit results right 4 bits for the ADS1015

  return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;  

Now that the config register is set, the i2c traffic asks the slave for the contents of the convert register.

 

..and there it is … both the Arduino and the nRF51 DK sent equivalent i2c traffic.  My iOS app wouldn’t know whether it’s talking to an Arduino or nRF51822.

 

Coding on the nRF51822’s I2C Module

Getting I2C traffic to work with the nRF51 SDK was similar to getting most apis I have been clueless about.  Unfortunately, while Nordic provides pretty good developer support, there is not the “geez this is easy let’s do it this weekend” type of tutorials that abound for the Arduino.  Getting out of the clueless state when it came to accessing I2C took longer than it might…of course, some of the cluelessness is innate to me.  

I’ll cut out the remarks and list what I found to be the most valuable things I learned:

  • the term to use when looking up anything to do with I2C is TWI.  This makes sense given this comment:  “The name TWI was introduced by Atmel and other companies to avoid conflicts with trademark issues related to I²C…Expect TWI devices to be compatible to I²C devices except for some particularities like general broadcast or 10 bit addressing.”
  • Use the latest SDK (in my case this is 8.1)
  • Stay away from using the Pack installer in Keil v5.  Packs make installing and maintaining drivers – like the TWI driver source – easy, peasy.  The challenge is a pack has a significant amount of dependencies.  Given the hours I spent trying to get my code to work by using Packs, I am not convinced the dependencies within the Nordic nRF51 DK packs are all correct.  I ended up downloading the SDK 8.1 zip (note: DO NOT download the file with Pack in its name).
  • use the nRF_drv_twi driver from the SDK.  This driver was released in SDK 8.1.  I found it simple and “just worked.” As noted in this post on the Nordic DevZone, there are previous versions.  Most of the DevZone posts relate to the previous versions (and…this tricked me up for awhile since I did not have the context on why there were three…which was the one to use…). 
  • check out the (extremely sparse 🙂 ) TWI documentation.   The example code snippet got me started on writing/reading over i2c.
  • it seems there was a “oops” that was caught after SDK 8.1 was distributed.  As noted in this devzone post, the following must be added to nrf_drv_config.h:
/* TWI */
#define TWI0_ENABLED 1
 
#if (TWI0_ENABLED == 1)
#define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL 6
#define TWI0_CONFIG_SDA 5
#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH
 
#define TWI0_INSTANCE_INDEX 0
#endif
 
#define TWI1_ENABLED 0
 
#if (TWI1_ENABLED == 1)
#define TWI1_CONFIG_FREQUENCY NRF_TWI_FREQ_250K
#define TWI1_CONFIG_SCL 0
#define TWI1_CONFIG_SDA 1
#define TWI1_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
 
#define TWI1_INSTANCE_INDEX (TWI0_ENABLED)
#endif
 
#define TWI_COUNT (TWI0_ENABLED+TWI1_ENABLED)
  • Choose between the TWI drivers, or use both.  In my case I am using the TWI0 driver.  I enabled this by setting #define TWI0_ENABLED to 1.
  • set the gpio pins for SCL and SDA.  I chose pin 0.06 for SCL and 0.05 for SDA.
  • If using Keil v5, get familiar with the (powerful) debugger.  I like taking a walk with the code…by stepping through the lines within the debugger and looking at the values within variables….I am at the n00b level of understanding this debugger.  Even with that, it is a far more pleasant debugging experience than within the Arduino IDE :-).
I ended up starting with the be_app_template_s110_pca10028 example within the SDK and added the following to main.c:
err_code = nrf_drv_twi_init(&twi,NULL,NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&twi);
rawADC = readADC_SingleEnded(&twi,0);
 
The function readADC_SingleEnded() is a porting of Adafruit’s function:

/**************************************************************************/

/*!

 @brief  A simple read of one of the four ADC channels.  Does not use the differential

 */

/**************************************************************************/

uint16_t readADC_SingleEnded(nrf_drv_twi_t const * const  p_instance,uint8_t channel) {

        if (channel > 3)

        {

            return 0;

        }

        m_bitShift = 4;

        // Start with default values

        uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)

        ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)

        ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)

        ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)

        ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)

        ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)

        

        // Set PGA/voltage range

        config |= m_gain;

        

        // Set single-ended input channel

        switch (channel)

        {

            case (0):

                config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;

                break;

            case (1):

                config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;

                break;

            case (2):

                config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;

                break;

            case (3):

                config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;

                break;

        }

        

        // Set ‘start single-conversion’ bit

        config |= ADS1015_REG_CONFIG_OS_SINGLE;

        

        // Write config register to the ADC

        // Note: currently block until write happens

        writeRegister(p_instance,m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);

 

        // Read the conversion results

        // Shift 12-bit results right 4 bits for the ADS1015

uint16_t valInRegister = readRegister(p_instance,m_i2cAddress, ADS1015_REG_POINTER_CONVERT);

        return valInRegister >> m_bitShift;  

}

 

/**************************************************************************/

/*!

 @brief  Writes 16-bits to an ADS1015 register

 */

/**************************************************************************/

void writeRegister(nrf_drv_twi_t const * const  p_instance,uint8_t i2cAddress, uint8_t reg, uint16_t value) {

    uint8_t tx_data[3];

uint32_t           err_code;

    tx_data[0] = (uint8_t)reg;

    tx_data[1] = (uint8_t)(value>>8);

    tx_data[2] = (uint8_t)(value & 0xFF);

 

    err_code = nrf_drv_twi_tx(p_instance, i2cAddress, tx_data, sizeof(tx_data), false);

    APP_ERROR_CHECK(err_code);

}

/**************************************************************************/

/*!

 @brief  Reads 16-bits from an ADS1015 register

 */

/**************************************************************************/

uint16_t readRegister(nrf_drv_twi_t const * const  p_instance,uint8_t i2cAddress, uint8_t reg) {

 

uint32_t           err_code;

// TBD: err_code (error handling) should be identical to all other nordic modules

          err_code = nrf_drv_twi_tx(p_instance, i2cAddress, &reg, sizeof(reg), false);

          APP_ERROR_CHECK(err_code);

 err_code =  nrf_drv_twi_rx(p_instance,i2cAddress,data,2,false);

                   

  value = (data[0] << 8) | data[1];

    return value;

}

That’s It For Now

While there were moments when my head hurt from banging it on my desk…thanks to previous efforts by Adafruit and folks on Nordic’s DevZone, I was happy to be able to get this working.  Especially given my weak coding skills and n00bness to embedded systems and their tool chains.  Having said all that, I am watching Apple’s WWDC 2015 videos…longing for a Swift playground that talks to all these SoCs /dev environments: Arduino, nRF51 DK….so that testing things out would be as easy as breadboard prototyping and looking at signals from a scope or DMM…well..now that Swift is open source…anyways…

 

 

Please find many things to smile about!

 
Advertisements

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Evolving the Ladybug Hardware

05 Friday Jun 2015

Posted by bitknitting in Arduino, BTLE, Ladybug Shield

≈ Leave a comment

Tags

arduino, BLE, bluetooth, Ladybug Shield

I think it is a combination of wanting to explore as I am becoming more experienced in electronics/embedded software, momentum behind devices using BLE to chatter amongst themselves and testing the wantcurrent Ladybug experience that got me to ask:

Does it make sense to replace the Arduino and Red Bear BLE Shield with a BLE module?  If so, which module?

Where the definition of a BLE module comes from this page on BLECentral:

…a small form factor PCB, ready to use, where not only the IC or SoC is already soldered, but also the required RF components (filters, antenna), oscillators and passive components. To top it off, many available modules also include a metal shield to prevent EMI and are certified according to the regulations in place in one or many regions of the world: Europe (CE mark), USA (FCC), Canada (IC), Japan (VCCI)… 

and the comparison of IC to SoC is:

  • SoC: (from the BLECentral page) A SoC is a single chip where the vendor has packaged all features one will usually need to address a specific market…one or more microcontrollers, static RAM memory, Flash memory, Bluetooth controller, RF transceiver, voltage regulators and tons of extra peripherals (analog to digital converters, timers, cryptographic processors…)
  • IC: the op amps, ADC, etc. that are mixed and matched…for example, all the active components of the pH and EC circuits.

The Goal

The goal of this post is to start the exploration in answering the above question.  This post will focus on the module.

Thanks to Those That Went Before

  • I am extremely grateful for Elicia White’s guidance.  I am a fan of her podcast Embedded.fm and her book “Making Embedded Systems: Design Patterns for Great Software”  as well as her element 14 blog posts, like the one she recently did “Bluetooth Low Energy, Three Ways.”  I had been getting up before the crack of dawn the last two days trying to get example apps to run on the nrf51 dk.  I asked for advice on the embedded.fm web site and WHOA…Elicia’s advice got me unstuck and running the example apps in an extremely short time.  Talk about a gracious and gifted technologist!
  • I will always be grateful to Chris Gammell for his Contextual Electronics courses and mentoring.  I would not be able to be able to design a schematic, do a PCB layout, or problem solve circuits without his guidance.
  • Adafruit continues to be an amazing resource for the maker community.  Adafruit is more than a place to buy a breakout board.  The folks there invest heavily in helping us learn about electronics, providing libraries so that writing sketches that use chips on the breakout boards extremely easy-peasy, and providing a community with tremendous support, enthusiasm.  I happily buy from Adafruit even when a breakout board might cost more because Adafruit provides not just a chunk of hardware, but a sense of quality and caring.  I recently purchased the Bluefruit which has emboldened me to jump into exploring the software/hardware around BLE – the communications method I use between the Ladybug iPhone app and device.
  • I can’t think of a company that I would rather do business with than OSH Park.  The OSH Park service, support, and team are role models on excellence other small businesses should work towards.

Current Hardware

Open Source

The Ladybug Shield Kicad schematic and layout files are located at this GitHub repository.

Block Diagram

The current hardware contains stuff that you might expect to see in a prototype:

Current Ladybug HW

The Ladybug iPhone app talks with the Ladybug device using BLE.  BLE is provided by the Red Bear BLE Shield that sits on top of an Arduino.  The Ladybug Shield sits on top of the Red Bear BLE Shield providing pH and EC voltage readings.  Many (at this point most) of the posts on this blog are about the evolution of design, testing, and implementation of the Ladybug Shield.  The The ADS1015 ADC sends voltage readings that represent pH and EC measurements over I2C.  The sketch on the Arduino sends a HIGH to one of three pumps when the control logic determines if the pH or nutrient amounts need to be adjusted within the nutrient bath. 

The Prototype Accelerated Progress

I am happy with this prototype approach.  It has allowed me to:

  • indulge my voracious appetite for learning. I am very happy with the amount I have learned this past year that would otherwise not have been possible.
  • enhance my hydroponics setups with automatic adjustment of pH and EC.  I am currently using and improving on the software as the prototype hardware is being tested in situ.
  • solidify the hardware of the protagonists – the pH and EC circuits.

Evolved Hardware Design

While I continue to evolve the Ladybug iPhone app, I want to also evolve the design of the Ladybug Device.  I do not see a current need to evolve the pH and EC circuits.  There is a great opportunity to evolve the micro controller and BLE components.  Instead of the Arduino as the micro controller and the Red Bear BLE Shield as the BLE component, I will be exploring using a BLE module like Raytac’s MDBT40 (data sheet).

New Ladybug HW The Nordic site lists several nrf51822 modules.

Potential benefits of replacing the Arduino and Red Bear BLE Shield with the BLE module module include:

  • Simplification of the Ladybug Device.  Instead of an Arduino Uno with the ATmega328  + Red Bear Lab BLE Shield with the Red Bear BLE land nrf8100 library from Notdic, the device shrinks down to be the BLE module (replacing both the Arduino and the Red Bear Shield) plus the current pH, EC, and pump circuits of the Ladybug Shield. 
  • Cost:  current costs:
    •  the Arduino Uno R3 = $25 
    • the Red Bear Lab BLE Shield = $25
  • Learning:  More YIPPEE!! moments ahead.  I’m already excited.
  • Evolved BLE: The Red Bear BLE Shield I am using uses the nrf8001 for BLE.  The nrf8001 is an earlier generation chip.  Besides correctly handling the BLE advertising packet (for example, currently I limit the name of a Ladybug to 10 characters and can’t use the advertisement packet to broadcast sensor readings), it integrates the ARM Cortex-M0.  This post provides a high level comparison between the two chips.
  • OTA-DFU (Over-The-Air Device Firmware Upgrade): From Nordic’s post: This feature allows application, protocol stack or, application and protocol stack to be updated wireless, over the air.

Testing the nRF51822

Development Board

I looked at two options:

  • the nRF51 DK development kit
  • Adafruit’s Bluefruit Bluefruit BoB.

The Bluefruit

Since I already had a Bluefruit, I started down the path of programming the nrf51822 on the Bluefruit.  Adafruit has pin outs that can be hooked up to a programmer on the back side of the Bluefruit (see Reverse Side Breakouts at this link):
Pin Outs - back of blue fruit
I’m new to all of this, so I asked on the Adafruit forum what I needed to program the nrf58122.  As usual, I got a great response:

get a Jlink  and connect to the SWD/SCK pins on the back, you’ll need the nordic SDK, available @ http://www.nordicsemi.com/
please note: we have zero support or tutorials for bare-programming the nrf58122

the plan was to solder jumper cables onto the SWC and SWD pins then plug the other end of the jumper cables into the SWD/SWC slots of the Jlink provided cable. 

The nRF51 DK

I ended up going with the nRF51 DK (link on digikey).  

nRF51 DK

Link to image

There is A LOT that comes with the development kit:

  • The Jlink is included on the board. Nothing else is needed to program or debug.
  • As noted on the Nordic site: “The kit gives access to all I/O and interfaces via connectors and has 4 LEDs and 4 buttons which are user-programmable.”
  • Also from the Nordic site: The kit is hardware compatible with the Arduino Uno Revision 3 standard, making it possible to use 3rd-party shields that are compatible to this standard with the kit.  I read this to mean I can test the Ladybug Shield using the nRF51822 instead of the Arduino and Red Bear Lab BLE Shield….YIPPEE!!!
  • mbed is supported if I wanted to give mbed a twirl.  For now my focus is on the nRF51822.

Development Environment

On to the software I’ll be running on my Mac for programming and debugging.  The toolchain assumes Windows.  While native Mac support would be very welcomed, it is not a show stopper.  I already use Parallels for Windows for Kicad and Quickbooks.  I followed the steps outlined in this post to set up the development environment.  More documentation on the Nordic SDK is given on this link.  This means I am using the Keil MDK IDE from Arm.  I could have also used an ARM GCC compiler.  
 
Note: one of the software packages is the Keil MDK IDE from Arm (download link).  I plan to use the Lite version, which is free.  It’s limitations are discussed  here.  The main limitation seems to be a code imitation of <= 32K.  Noted in this post:

Most applications will actually fit inside 32k because of the architecture and SDK that Nordic provides. If you need more than 32k, there is always Eclipse and GCC.  This version of the IDE can be used in commercial products as discussed here.   While the Keil MDK IDE is not as comfortable to use as iOS’s XCode – especially since I develop on a Mac – I found it to have nice features – like the Pack Installer and symbolic debugger.

Time to Blink

Time for the HELLO WORLD app.  There are many examples that come with the Nordic SDK.  The Keil IDE includes a Pack Installer that makes it incredibly simple to get an example up and running.  Simpler than at least the previous version of the Arduino IDE where to get 3rd party examples to work means copying the libraries + examples to “the right” location with no visualization of what has been copied and no flexibility to where the examples + libraries are copied.
 
I followed the tutorial recommendation and tried out the ble_app_uart_s110_pca10028 (UART over BLE application).  I wasted some time not grasping what s110 was all about…I found it important to understand the implications of a SoftDevice.  This image allowed me to get my head around the s110.  It’s great that the s110 is in a fixed memory location and does not take away from the 32K restriction.
 
I got the example running and then installed the nRF Toolbox (for iOS) on my iPhone….and…a YIPPEE!! moment…it worked.  WHOA.
nRF Toolbox UART example
 

That’s it for Now

I need to get back to my Contextual Electronics work/study as well as the Ladybug iPhone app.  Not to mention I designed a PCB for an LED system I’m working on.  I am excited to continue exploring an nRF51822 module as a replacement for the Red Bear Lab BLE Shield and the Arduino within the Ladybug device.

 

 

THANK YOU for reading this far.  Please find many things to smile about.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Progress update on Ladybug Shield

25 Monday May 2015

Posted by bitknitting in debugging

≈ 2 Comments

Tags

Ladybug Plant Food Adjuster, Ladybug Shield

 

A few updates….

 

I’m starting to use the Ladybug Plant Food Adjuster on a lettuce setup.  I’ll post more details on the setup in another post.

Thumb IMG 3554 1024

I’m excited to say the system is working well.  There are bugs particularly in the iOS app.  For example, the iOS app writes each reading to a CSV file.  When the app runs in the background, data collection stops.  I updated the app to support BLE background reading (and while at this updated to support state preservation and restoration in the case iOS needs to terminate the Ladybug app due to low memory…hard for me to believe the grower is running more important apps 🙂 – yah right!).

Change to Ladybug Shield

A change I made to the Ladybug shield was shrinking it’s size.

Size comparison of Ladybug Shield between beta 3 and beta 4

The smaller size was $9 less when ordering the 3 boards from OSH Park.  My original plan was to not force the Ladybug Shield to be the top shield by sticking out the BNC connectors.  As I was using the board, I found shields come in all shapes and sizes.  It seemed no matter how long I made the shield, there is another shield that didn’t sit well when the Ladybug shield was below.  In particular, currently I am using the Red Bear BLE shield.  This shield is a tad too long for the BNC placement.  So I shrunk the board mostly because of what I consider a significant cost savings.  I did not see a use case compelling enough to (most likely) expand the board to justify the additional cost of PCB fabrication.

Although in the process I could have handled the artwork better:

1505250731 0

oops! trace goes over OSHW logo

I’ll fix this on the next rev of the board…. 

Change to Cabling Between Enclosures

I haven’t spent much time on enclosures and cabling.  I want to focus on starting to use the plant automator and then evolve the different parts of the experience.  Initially, I had strung together some wire between the two enclosures so that the shield could send pump on/off signals to the pump box.  Moving both units around is difficult so I am trying a Molex (5.25 Male) / Molex(2X 5.25 Female) Power Splitter from monoprice.  

Thumb IMG 3552 1024

 

NewImage

So far so good on the connectors.  I hope to find them for less from a distributor that just sells the connectors.  I went this route because I am more familiar with the wiring in PCs.  I knew if I tried these the right fittings would be there.

 

 

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Introducing the Ladybug Plant Food Adjuster

05 Tuesday May 2015

Posted by bitknitting in EC, Herbs, Hydroponics, Ladybug Plant Food Adjuster, Ladybug Shield, pH

≈ 4 Comments

Tags

EC, Ladybug Plant Food Adjuster, Ladybug Shield, pH

I’ve put the Ladybug Shield together with other hardware and software to implement a kitchen farmer plant food adjuster.  For now I am calling this the “Ladybug Plant Food Adjuster.”  I am currently testing/using it in my home.

The home farmer will be growing lettuce, herbs, tomatoes… within their home,  likely the kitchen.  This is in contrast to the more expert hobby or professional that has “industrial capable” pH, EC – and other probes, honking LEDs,…i.e.: knows A LOT about growing vegetables and herbs and needs super fine control of plant food adjustment.

Thanks to Those That Went Before

It is difficult for me to imagine being able to build the Ladybug Shield (see previous posts) without Chris Gammell and Ryan (@SparkysWidgets).

  • Chris Gammell runs the exceptional Contextual Electronics courses.  While I pay for the privelege, it is indeed a priviledge to feel and be treated like an apprentice.  Besides shear learning in a supportive and peer environment, Chris’s 1:1 time has been valuable/insightful/amazing in shaping the design of the electronics of the Ladybug Shield.
  • Ryan open sourced his minipH and miniEC stamps.  I poured over Ryan’s design until I understood them.  I had no idea how a pH or EC meter worked.  Ryan’s work significantly simplified what I needed to learn and my approach.  ON TOP OF THAT, Ryan is a truly great and very helpful person.  Please support Ryan!
While there are many great companies, two have made a HUGE POSITIVE impact on this project:
  • OSH Park the most excellent producers of low volume (purple!) PCBs.  OSH Park has the most amazing support and personal service.  From the CEO (Laen) to the support person who took his efforts in helping me out to the next level (Dan) – if I must part with my money, there is no better company/service/group of folks.
  • Adafruit, providers of breadboards, all sorts of circuit creation “thingies” that are too cool not to buy, exceptional tutorials, libraries for chips (like the ADS1015 ADC I used on the Ladybug Shield) that work within the Arduino IDE, and terrific support on their forums.  EVERY post I have made has got a valuable response.  What a great company.  
Then there are podcasts, videos, and a slew of web pages that have willingly shared their knowledge.  A particular shout out goes to Elicia White, co-host of the Embedded.fm podcast.  She wrote a blog post on a question I asked that was very useful for me.  Now – there have been many more.  Elicia’s insightful answer is the most recent.

What The Ladybug Plant Food Adjuster Does

The Ladybug Plant Food Adjuster automatically adjusts the nutrient and pH level of a reservoir of water (the hydro part) feeding growing plants.  It is for people like me that enjoy fresh vegetables and herbs.  We have many reasons to supplement what we buy with what we grow in our kitchen.  While I garden both indoors and out, I live in an environment that does not support growing vegetables and herbs year round.  Besides, in the winter it is rainy and cold.  During the winter I don’t want to spend time in an outdoor garden but love being surrounded by healthy growing plants in my kitchen.

The Components

The Ladybug plant food adjuster consists of:

Ladybug plant food adjuster

  • The probe box:
    •  measures the pH and EC values in the reservoir of water being used to feed the plants.
    • communicates with the iPhone app (using BLE 4.0) updating the app with pH and EC measurements.  The iPhone app controls the probe box by setting what type and stage the plant is in (in the diagram above, the type of plant is tomato and the stage is Youth.  The type and stage set the values for the set points which will be used by the pumps to figure out if they are far enough away from the set point to add a dose of either pH adjustment or EC concentration).
    • communicates with the pumps (using wires) to turn on either the pH or nutrient pump if the readings are off too much from the set points.  It knows to add nutrients before pH adjustment since additional nutrients will change the pH level.  This is an example of “working smart for you.”
  • The pump box:
    • contains a pump to add nutrients and a pump to adjust the pH level.  It is controlled by the probe box (the “brains”)
  • The iPhone app (is currently really really ugly…but works on my iPhone and iPad.  The goal is to be functional for testing.  Design will follow function):
    • connects to the probe using BLE 4.0
    • gets info from the probe on what it is monitoring (plant type and stage) and whether the pumps are currently allowed to be pumping or should be off (regardless of the pH and nutrient level in the reservoir).  It uses this info to update the display
    • lets the grower set the name of the plant as well as the plant type and stage.
    • displays the most recent readings for pH and EC as well as the set points.  This way the grower can see if current measurements need to be adjusted
    • informs the probe whether to turn off or on pumping.  If pumping is turned off, the probe will not tell the pumps to turn on even if the measurements need adjustment.
    • lets the grower export then email the readings into a CSV file.

The Ladybug Plant Food Adjuster Hardware

Hardware includes an iPhone/iPad as well as the probe box and the pump box.

The Probe Box

Inside the probe box is an Arduino Uno with a Red Bear BLE shield and Ladybug shield attached to it.

IMG 3430

The schematics and layout (Kicad) are located at this GitHub repository.  Designing and implementing the shield was my way to learn electronics, making a PCB, the math / science / electronic design of pH and EC sensors.  It was – and continues to be – a very positive experience!   Please see the many earlier posts I have done detailing what I learned/what I ended up implementing and why.

IMG 3434

A pH and EC probe are attached to the Ladybug shield using the BNC connectors.

The back end has holes carved out for:

  • cable to 12V wall wart.  A 12V Wall wart powers both the pumps as well as the Arduino
  • the USB cable used by the Arduino.  This is optional.  I use it while debugging to print out to the serial monitor.
  • the wires that attach to each pump.

The Pump Box

The pump box contains two peristaltic pumps, one for adjusting the pH level and the other to adjust the nutrient level.  

IMG 3433

Wires – originating from the Probe Box connect the pumps to the Probe.  The Ladybug Shield uses the 12V wall wart to power the pumps.

How the Ladybug Plant Food Adjuster works

At the core of the Ladybug Plant Food Adjuster is the reservoir containing water with the nutrients set at the right pH level.  We start with a bucket.  It can be any bucket.  For now I’m using Rubbermaid.

IMG 3443

 

One of the Rubbermaid Buckets I Use

 But I have bought much nicer looking reservoir/hydro systems.

IMG 3442

Nicer Looking Bucket Growing Basil on Kitchen Counter

 

 My goal is to evolve into happy designs that please the grower.  Right now I am at the “Frankenstein” phase.   While single plant setups are “easy”, each would take its own Ladybug Plant Food Adjuster.  I will start using the Adjuster to grow about 6-12 heads of lettuce.  

I fill the bucket up with filtered water.  The less minerals/salts the better since the amount of nutrients is a measurement of the conductivity of the salts in the water (discussed perhaps more than you wish in previous posts).

I add an air stone to increase the amount of dissolved oxygen.  After all, plants need to breathe.  

Next, I attach a pH and EC probe to the Probe box and place the probes into the filtered water.

It’s time to mix up the pH and nutrient concentrations that the Pump Box will add to the filtered water until the EC and pH values are at healthy levels for the plant type and stage (of life).

Plant Food

I’ll use the term “plant food” when referring to the nutrient concentration.  Once the plant food is available for pumping, the Ladybug Plant Food iPhone app sets the recommended levels for the pH and EC.  The (yah – I know – extremely ugly…) setup screen of the iPhone app uses a UIPickerView to let the grower tell the Ladybug Plant Food Adjuster what type and stage the plant(s).

Ladybug app settings screen

The Settings Display of the iPhone app

  The image shows “Tomato/Youth” – this tells the Adjuster what the pH and EC levels should be.

As an example, here is my tomato/youth plant I am growing.  We call it/him/her? Tommy.

IMG 3440

Tommy Doesn’t Know What Day it is

What the “right” food is to feed a plant is based not only on scientific reasoning  but also what works best for you and how much you are willing to pay.  I started off using liquid fertilizers like the one I linked to from Amazon (if you click on the link and buy something I get an Associates fee – what the heck, that’s why this ad prominently placed below): 

//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=bitknittingwo-20&marketplace=amazon&region=US&placement=B0024NDVRA&asins=B0024NDVRA&linkId=KVTIJMSR3MCUUE3Q&show_border=true&link_opens_in_new_window=true

As my knowledge evolved, I started using the product and advice from Hydro-Gardens.  The site has information on food and additional chemical compounds as well as the amount for several vegetables.  For example, here is the “recipe” for growing tomatoes.  I got the dry ingredients and then mix up the amounts for whatever it is I am growing.

IMG 3441

Dry Ingredients I Mix together to Feed a Young Tomato Plant

Now that I have the mix I need for growing a young tomato, I put many (I put around 5) scoops into the container and fill the container with filtered water.  The pump’s nutrient feeder hose is stuck into the plant food.

IMG 3444

 

The Plant Food Container 

I will stick the nutrient feeder hose into.  It is challenging for me to get all the particles mixed well. I’ve tried integrating mixing into an exercise routine.  At some point I need to think of “best ways” to mix the plant food.  I’d also like a better suited container.  I had just finished the contents of a salsa container so it became the plant food container – at least for now.

pH

The Ladybug app knows to adjust the nutrient level before adjusting the pH.  The additional nutrients will change the pH of the water.  Once the nutrient level has been reached, the Probe goes through adjusting the pH level.  In all cases that I have come across, the pH of the water needs to be adjusted down.  This is why I use only one pH dosing container.  Which also happened to have held salsa…hmmm…too much salsa?  Nah…never…

IMG 3445

the pH concentrate is about a tablespoon of pH DOWN with water.  The concentration of Hydronium ions – which is what is being added to lower the pH level – is very intense.  This is why I dilute from pH down.

There’s an App for That

I decided to talk to the reservoir through an iPhone app.  I use the iPhone and have a developer’s license.  The app uses Apple’s Core Bluetooth framework to talk via BLE 4 to the Probe Box.  The probe box sends whomever it is connected to (in this case my iPhone running the Ladybug app) updated measurements as well as the ability to turn pumping on/off as well as select the plant type and stage.  I envision in most cases leaving the pump state on and letting the Probe Box determine if more dosing is needed.

Ladybug app home screen

 Settings were discussed earlier – see the settings screen shot.

I wanted to evaluate the data so I added the ability to export and then send what has currently been logged in a data base.  I then use a spreadsheet program to take a step back and see how well feedback and adjustments are going.

That’s it.  The app has two screens.  

What’s Next

It is hard to describe the sense of joy I have coming this far.  I’m setting up a reservoir for 6-12 lettuce.  I’m off to get that going and to plant lettuce seeds.

 

 

THANK YOU for reading this far.

Please find many things to smile about.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

That’s a Wrap (for now) Ladybug Shield Beta 2

13 Monday Apr 2015

Posted by bitknitting in Ladybug Shield

≈ 5 Comments

Tags

EC, Ladybug Shield, pH

 Ladybug Shield Works – Open Source Available

Totally a YIPPEE! moment.  All circuits on the Ladybug Shield are working.  pH and EC values get reasonable measurements.  Pumping works.  WooHoo…

IMG 3409

Just back from OSH Park

IMG 3417

Check out the Awesome soldering Job Thanks to the Zallus Reflow Oven Controller

IMG 3415

Ooh—OOH – IT WORKS!—time to work on enclosures…

Open Source

Arduino and Kicad files are located at this GitHub location.

Thanks to Those That Went Before

I would not have the skills to do this without the teachings and mentoring of Chris Gammell and his Contextual Electronics courses.  There was A LOT to learn (still is of course).  Chris and his courses greatly accelerated the process.

Regarding skill, thanks to Ryan (SparkysWidgets) for open sourcing the minipH and miniEC.  The EC and pH designs of the Ladybug Shield evolved from Ryan’s work.  Besides that, Ryan has been super helpful.

A terrific company that has provided an invaluable service and EXCELLENT support – OSH Park.

A very useful reflow oven controller from Zallus.  Works GREAT!  My soldering skills skyrocketed with this addition.

 

 

 

Wow.  I think that’s a wrap for the Ladybug Shield….I’ve started using them….a total YIPPEE! moment.

 

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Ladybug Shield Beta V1 – Cleaning Up the Design

27 Friday Mar 2015

Posted by bitknitting in Ladybug Shield

≈ Leave a comment

Tags

Ladybug Shield

I finished testing the Ladybug Alpha V2….for the most part all works.  Still there is more to fix.  I just sent Beta 2 off to OSH Park.  I skipped Beta 1.  I had done a version where I had removed the pump circuits.  I decided to put these back in after testing the pumps.

The Goal

The goal of this post is to document changes to Ladybug Alpha V2 that change the schematic and layout.  

 Thanks To Those That Went Before

  • Thanks to OSH Park for their exceptional PCB fabrication and support.  OSH Park is excellent at keeping customers happy.  OSH Park – thank you for your exceptional support and company culture that makes me want to support you as a company.  Thanks to Embedded.fm’s interview of Laen – OSH Park’s CEO – I now know that it is OSH and now Osh.
  • Thanks to Adafruit for their excellence in support, tutorials, and open source availability of schematics/layout.  This post borrows the design for a single power source in Adafruit’s motor shield.  Adafruit has done an excellent job not only selling to, but supporting and caring about customers.  I know when I have a question and post it on the forum – one of the incredibly knowledgable and kind folks (typically Mike or Bill) respond in a small amount of time – along with great answers from folks that are not employed by Adafruit.  Adafruit – like OSH Park – are high on my list of companies to buy products from.  The products are of great quality, come with excellent additions – like libraries for Arduino programming, tutorials, and are well supported.
  • As always, thank you to Chris Gammell.  I am continuing to learn A LOT from Chris’s Contextual Electronics courses.  I like the new format where we work on smaller projects together.  Each one has given me many opportunities to strengthen my knowledge…well, I try anyways.
  • Ryan of SparkysWidgets fame has a great product in his minipH and miniEC.  I recommend these break out boards.  It is what I evolved my designs from.  Thank you for your open source schematics and Arduino sketches.  Ryan is extremely helpful and kind.   Thank you.

Open Source

The Kicad files for the Ladybug Beta V2 are located at this GitHub location.

Beta 2 Changes

Changes from Alpha 2 to Beta 2 include:

  • changes to how the components as well as the pumps get power.
  • removal of temperature readings.
  • addition of test points.

The Power Design

The current design:

  • includes a voltage regulator between the Arduino’s VIN and the 5V used by the pH and EC circuit.
  • assumes two power sources.  One for the pH and EC circuit (5V) and one for the pumps (12V).
The Ladybug Shield Beta 1 will clean this up, removing the voltage regulator and the need for two power sources.  The design will borrow from Adafruit’s power source on their motor shield.  Here is an image of part of the AF_mshield_v12.sch: 
Pasted Image 3 25 15 10 08 AM

A 12V Wall Wart will be plugged into the Arduino’s barrel jack.  The 12V Wall Wart will power both Arduino’s 5V power supply as well as power the pumps.  While there are three pumps, the pumps will not be used at the same time.  For this reason the pumps will share a power source.   A nice aspect of Adafruit’s design is the lining up of GND such that both the 12V and Arduino’s 5V voltage sources are relative to the same GND.  My earlier attempts mistakenly did not align Arduino’s GND with the pump’s power source GND.  Well, it did help me understand what is meant by aligning the GND….  

From the FAQ section of Adafruit’s motor shield documentation:

My Arduino freaks out when the motors are running! Is the shield broken?

Motors take a lot of power, and can cause ‘brownouts’ that reset the Arduino. For that reason theshield is designed for seperate (split) supplies – one for the electronics and one for the motor.Doing this will prevent brownouts. Please read the user manual for information about appropriatepower supplies.

Adafruit’s design accommodates this by using a jumper and including a 2-terminal block for the V+/V- of a power supply.  When the jumper is not on the shield, the pumps use an external power source.  The “standard” power source – USB or a power source plugged into the barrel jack – is used for circuits on the shield that use the Arduino’s 5V power source.  The GNDs of the two power sources is aligned.

I’ll also make a small modification to add a green LED on the line to detect if the shield is getting power.  

Temperature

I decided to not use temperature to adjust the probes.  Even though measuring pH is all about figuring out the amount of H+ ions clinging to the probe’s glass membrane.  When the temperature of the nutrient bath varies from the ideal of 25˚C, the amount of H+ ions changes.  I experimented adjusting the temperature and decided not remove the thermistor circuit for measuring temperature.  I made this decision:

  • I’m growing plants in my house. The water temperature will not vary much.  Perhaps the lighting will warm up the nutrient bath.  However, I am using LEDs.  LEDs do not dissipate much heat.
  • The measurements need to be precise, but inaccurate and span a range of values.  
  • While there will be a .1 inaccuracy, the leafy plants I wish to grow with the help of the Ladybug shield are cool-season vegetables.  As noted in this article, a healthy temperature range for a nutrient bath supporting cool-season vegetables is between 10˚C/50˚F and 21˚C/70˚F.  I will use 10˚C for my rough calculations since it is farthest away from the ideal 25˚C.  When the nutrient’s bath is at 25˚C, the amount of voltage between pH values is 59.16mV.  When the nutrient bath’s temperature is at 10˚C, the voltage between pH values is 59.16+(10-25)*.198 = 56.19mV, close to 3mV.  Since the resolution of the ADC set to 1mV LSB works well, an Arduino Sketch will be able to pick up this difference.  I would address this difference if I required both precision and accuracy.

for the environments in which I will be using the Ladybug Shield, the temperature will not vary enough from 25˚C to include temperature adjustment.  While the readings would be more precise, the range that is allowed for healthy growth is large enough that introducing the additional will not affect growing healthy plants.

Test Points

I am finding it difficult to look at two signals on a scope if the contact for the probes is one of the chip’s pins.  Now that I have a better idea on what to test, I am putting test points at the places I have found myself constantly measuring – the EC and pH inputs into the ADC, each phase of the EC signal processing.

 

Just a short update so that we’re on the same page on what the Ladybug shield is shaping up to be.  If this version passes tests, I should be close to completing the hardware!

 

 

Thanks for reading this far.  Please find many things to smile about.

 

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Getting pH readings on my iPhone from the Ladybug Shield

23 Monday Mar 2015

Posted by bitknitting in BTLE, Ladybug Shield, pH

≈ Leave a comment

Tags

BTLE, ios, iphone, Ladybug Shield, pH

As I get older, I evolve choices to which make me happier.  Perhaps selfish but life is so incredibly short…why not surround each other and ourselves with happiness?  Using my iPhone to interact with the Ladybug Shield makes me far happier than using an LCD.  Besides, programming in Swift is..well…fun….at least fun relative to other programming languages I have bumbled about.

I want to start using the Ladybug Shield around my house.  This “forces” me to get my nose out of the scope and into the UI.

The Goal

The goal of this post is to go through the process of building a minimal iPhone app that display pH and EC readings from a Ladybug Shield.

Open Source

The Arduino and XCode files are located at this GitHub location.

Adding BLE

The Ladybug Shield does not include BLE.  After many starts and stops, I ended up adding the RedBearLab BLE Shield.  

IMG 3383

 

 

I spent too much time trying to get the Bean to work (which I had used in a previous prototype).  Ultimately, the Bean could work, but the challenges that got me to decide on using the RedBearLab BLE Shield over the Bean for this prototype included:

      • getting a stable/solid wire connection between the Bean and Arduino over the I2C pins.  At one point I soldered header pins onto the Bean’s holes which screwed up the board….I ordered another….yah, D’OH mistake :-).
      • The Ladybug Shield uses the ADS1015 – another I2C device.  I use Adafruit’s ADS1015 library which assumes the ADS1015 is the master.  This means both the Arduino and the Bean must act as slaves.  This was ok, but complicated my coding.
      • The Bean is a 3.3V device. The Ladybug Shield and Arduino are running at 5V.  I was running into communication over I2C freezing when the ADS1015 and Bean were both involved.  Yes, I could add a level shifter as I have done in the past…but it is one more thing to deal with. 
      • The Bean needs an external power supply.  The easiest is to use a C-Cell battery.  My bad was to keep leaving the Bean on with the battery in.  I’d come back in the morning to yet another dead battery.
      • The Bean must use the older (1.0.5) version of the Arduino SDK.  In general these type of 3rd party dependencies become necessary evils.  While the Bean’s abstractions make getting a BLE app between the Arduino and an iPhone easier, the cost of not being able to update the SDK is high for folks that have at least an intermediate level of BLE programming.
      • The RedBearLab shield uses the nrf8001 BLE chip (data sheet).  I gave up a more friendly library of APIs, being “forced” to gain familiarity with a library for the nrf8001.  My BLE requirements are very minimal so it didn’t take me much time to get the Arduino sketch pumping out pH and EC readings over BLE.

The ReadBearLab shield uses SPI.  Instead of using a CS pin, it has two pins – REQN and RYDN.  As noted in the nrf8001 data sheet:

However, nRF8001 does not behave as a pure SPI slave device; nRF8001 can receive new data over-the air at any time or be busy processing a connection event or new data. Consequently, the traditional CSN signal used to initiate an SPI transaction is replaced by two active low hand-shake signals; RDYN andREQN  

Nordic Semi’s library (for Arduino)  defaults REQN and RYDN to pins 8 and 9. These can be set to any of the pins 2 to 10.  For this prototype the Ladybug Shield will work with the default pins.

Sending pH and EC Over BLE

I did not need real time readings so I decided it was good enough to package the pH and EC value in the RedBearLab’s advertisement packet.  I should be packing the readings into the data portion of the advertisement packet.

 

BLEPacketFormat

This shouldn’t be too hard once some amount of familiarity with Nordic’s interface – Application Controller Interface (ACI) is accomplished. if I follow the steps outlined in this support post:

  • Once the nRF8001 sends the ACI Device Started Standby event, you can use the ACI OpenAdvPipe command (lib_aci_open_adv_pipes) on the broadcast pipe.  When you are opening a pipe using the ACI Command OpenAdvPipe, you need to wait for the Command Response Event [that says the pipe is open…not just that the request was queued]
  • update the data in the Pipe by using the ACI Set Local Data command ( lib_aci_set_local_data)
  • Then start advertising using the ACI broadcast command.
These steps point out what is going on within a figure in the nrf8001 data sheet that discussing setting broadcast data:
setnrf8001bcastdata

Since this effort is “quick and dirty” I decided to set the RedBearLab’s peripheral name to the pH and EC values.  The details are covered in the Arduino sketch LadybugShield_BLESlave_V1.ino:

void loop()
{//don't do anything until BLE is ready
  if (ble_isAdvertising())
  {
    float pH_value = takepHReading();
    DEBUG_PRINTF("--> pH: ");
    DEBUG_PRINTLN(pH_value);
    uint16_t EC_value = takeECReading();
    DEBUG_PRINTF("--> EC: ");
    DEBUG_PRINTLN(EC_value); 
    setBLEAdvertisementName(pH_value,EC_value);   
    DEBUG_PRINTLNF("Wait before taking another reading...");
    delay(10000); //take a break
  }
  ble_do_events();
}

I did modify the nrf8001 library to:

  • include ble_isAdvertising() to let the Arduino sketch known that the “ACI advertisement has begun event” has occurred.  
  • set the peripheral name:

        lib_aci_set_local_data(&aci_state, PIPE_GAP_DEVICE_NAME_SET , (uint8_t *)&device_name , strlen(device_name));

 iPhone App

 The (very ugly) iPhone app picks up the advertisement packets and displays the pH and EC value.  

IMG 0044

Ugly iPhone app Running on my iPad

 

I used an updated BTDiscovery class library I had used in a previous prototype to receive the advertisement packets.  The swift file is BTDiscovery02072015.swift.   The BTDiscovery class includes delegates that are implemented by the View Controller (ViewController.swift) to update the pH and EC labels on the UI.  Easy Peasy.  Did I mention how much I like the Swift language?

 

 

 

 

Thanks for reading this far.  Please find many things to smile about.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Ladybug Shield Alpha V2 – Comparison with Atlas Scientific EZO EC Stamp

12 Thursday Mar 2015

Posted by bitknitting in Atlas Scientific, EC, Ladybug Shield

≈ 4 Comments

Tags

Atlas Scientific, EC, Ladybug Shield

And now for the exciting part….comparing EC readings between the Ladybug Shield and Atlas-Scientific’s EZO EC Stamp.  Yes, I designed the Ladybug Shield for a different use case than the EZO EC Stamp.  But I thinking of the EZO EC Stamp as a “gold standard” of Arduino EC sensors.  Also, I use an Atlas-Scientific probe so both measurements will be using the same probe.

The Goal

The goal of this post is to compare EC readings when the Atlas-Scientific EC probe (K=1) is submerged in:

  • 2000µS
  • 1413µS
CalibrationSolutions
calibration solutions.

Thanks to Those That Went Before

A huge thank you to Chris Gammell for mentoring and teaching his excellent Contextual Electronics courses.  A year ago I would not have dreamed I would be able to build the Ladybug Shield.  I give Chris the credit for getting the EC circuit to work in key areas – like advising to measure Vin as well as Vout.

Another giant thank you to Ryan @SparkysWidgets.  Ryan open sourced the design of the minipH and miniEC.  I absorbed and evolved these designs into the Ladybug Shield.  Ryan has been extremely helpful in my efforts.

Use a K=1 EC Probe

The protagonist of any EC measurements is the probe.

Conductivity probes that I am aware of have these dimensions:

ECProbeDimensions

Probes may vary in the distance between the electrodes.   EC = (the distance between electrodes/area of an electrode plate) * conductance.  The distance between electrodes/area of the electrode plate is known more commonly as the K constant, or just K. A probe with K=1 has 1cm distance between electrodes with 1 cm squared area of electrode plate.  I started with a probe with a K=.1. I figured a shorter distance between the plates would amplify the incoming signal and therefore get better readings.  I found however the design of the Ladybug Shield’s EC circuit was better suited for a K=1 probe.

Here is an image of the EC Vout when K=.1:

CalibrationK01

The gain loop is amplified to the point where the peaks are chopped.

Here is an image when K=1:

K=1Waveform

 

 My probe has a K of .1/cm -> .1cm distance between electrodes/1 cm squared area = .1/cm.  Since the electrodes are closer together, the probe can be used in lower conductivity solutions than a probe where the K=1.  Until I know better, a probe with either K=1 or K = .1 should work.

Tables for EC values of vegetables have a nasty habit of leaving off the distance, assuming the probe has a K of 1.  For example, a page that lists EC values for vegetables notes: Electro-Conductivity (EC) or Conductivity Factor (cF) can be expressed as… milliSiemens (mS).  This is true if K = 1.  When K = .1, EC = K *conductance. The table lists the EC value for lettuce to range from .8 to 1.2mS.  When K = .1, EC = .1*.8 to .1*1.2 = .08 to .12mS

Readings

The Ladybug Shield and the A-S EZO EC Stamp used the same K=1 EC probe.

K=1ECProbe

Comparison

The table below shows the µS value for the EZO and Ladybug Shield when the EC probe is in a 2000µS and then 1413µS calibrated solution:

Calibrated Solution Ladybug % difference EZO % difference
2000 2059 2.91 1875 8.42
1413 1388 1.79 1254 15.68

The results seem too good to be true.  The Ladybug results were very close to the calibrated solution value.  Talk about a YIPPEE! moment….

The biggest change in the Ladybug shield to get better results was the reading of Vin (the shrunken signal generated through the Wien Bridge Oscillator).  As I noted earlier, Since both the Vin and Vout are key variables in calculating the Gain – it makes sense to measure both.

Ladybug Calculations

In the case of the 2000 µS calibrated solution, Vin = 239mV  Vout = 731mV.   Gain = 731/239 = 3.058577406. R = 1000/(3.058577406-1) = 485.77235769 Ω EC = 1/485.77235769 = .002058577 S = 2059µS.

In the 1413µS solution, Vin = 237mV Vout = 731mV  Gain = 566/237 = 2.388185654 = R = 1000/(1.388185654-1) = 720.364741646Ω EC =  1/720.364741646 = .001388186 S = 1388µS.

That’s It For Now

The EC circuit appears to be working.  A Definite YIPPEE! moment.  

 

 

Thanks for reading this far.  Please find many things to smile about.

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Ladybug Shield – A Better Understanding of The Interaction Between the MUX and FET

05 Thursday Mar 2015

Posted by bitknitting in Ladybug Shield

≈ Leave a comment

Tags

Ladybug Shield

I recently modified the EC circuit to read both Vin and Vout of the EC gain loop.  This way the Ladybug Shield would provide the closest readings for the Gain (Vout/Vin).  Once the gain is known, the resistance of the EC probe in the nutrient bath can be measured.  Once the probe’s resistance is known it is a small skip to calculate the Conductivity of the nutrient bath.

Thanks To Those That Went Before

  • Chris Gammell advised me on how to think about and debug this challenge.  Chris is an excellent teacher/mentor.  I have learned A LOT from his Contextual Electronics courses and his mentorship.  THANK YOU.
  • Ryan (SparkysWidgets) open sourced the minipH and miniEC.  This effort has allowed me to gain a jump start in my understanding of the electronics behind pH and EC circuits.  Besides that, Ryan is an exceptionally smart, kind person who readily shares his knowledge and has provided me with excellent advice.  THANK YOU.
  • Laen and the people/company at OshPark.  I have become an advocate of OshPark.  They are a model of the most excellent service/support providing quality product at a reasonable price and turn around time.  THANK YOU.

Open Source

The kicad schematic and layout are located at this GitHub location.  The schematic to view for this post is the Rectifier schematic.

I recently started measuring both Vin and Vout of the EC gain loop.  

RectifyCircuit

The Challenge

For weeks I have been poking at really understanding why I am seeing readings from the ADC start high and eventually drift down to the right value when these events occurred:

  • switch MUX to take Vout readings
  • turn FET on for around 4 ms to drain the capacitor
  • switch MUX to take Vin readings

Challenge 1: Start high, Go low

Vin readings start out high (say around 900mV) and eventually (after hundreds – say 2000 readings) stabilize at an expected value (say around 250mV).

I stumbled around mumbling what I thought was going on.  The problem was I didn’t have “the smoking gun.”  I didn’t have proof of what was going on until….until…I gained a better understanding of how to use a scope!

Chris advised me what to look for:

On channel 1, monitor the gate voltage of the FET.On channel 2, monitor the input to the buffer (the output from the rectifier circuit).
If you trigger on channel 1 going high, you can see the behavior the FET is causing (hopefully draining the cap). 

(RIGHT THERE – the cost of Contextual Electronics paid off !)

Ah yes…just like any great detective knows…figuring stuff out is about figuring out what to look for and then finding it.

After figuring out the difference between “Auto” “Normal” and “Single” triggering I realized what I wanted was to set my scope on Normal triggering.  Personally, I found (find?) how triggering works confusing at first.  But well worth learning :-).

And look at that:

FET Trigger HIGH

The blue line follows the FET as it transitions from OFF (low) to ON (high).  When the FET is on, the cap is discharging.  The yellow line starts reading the rectified Vout and then switches to Vin at about the time the FET is set to HIGH.  It turns out the cap discharges in about 25µS.  With the FET on HIGH, the cap is kept discharged.  

I then set a trigger to happen when the FET went to LOW using an Arduino sketch that executed one after each other:

digitalWrite(FET_pin,HIGH);

digitalWrite(FET_pin,LOW);

The scope showed the capacitor was fully discharged within the time it took the Arduino sketch to execute the digitalWrites():

FETHIGHThenLOW

Given the small amount of time it takes to discharge the cap, a digitalWrite(FET,HIGH) immediately followed by a digitalWrite(FET,LOW) gives more than enough time to discharge the cap (about 80µS for the code to execute while it takes about 25µS for the cap to discharge).

Challenge 2: Settling Down

Another challenge I was facing with ADC readings was slightly higher readings right after turning the FET OFF.  So I took another scope measurement.  This time I ran an Arduino Sketch that:

byte S = HIGH;
Serial.println(“send VOUT for 1 seconds”);
digitalWrite(FET_pin,LOW);
digitalWrite(MUX_pin,S);
delay(1000);
S = LOW;
Serial.println(“Switch to VIN”);
digitalWrite(MUX_pin,S);
//turn FET on and off to discharge the capacitor
Serial.println(“FET ON”);
digitalWrite(FET_pin,HIGH);
Serial.println(“FET OFF”);
digitalWrite(FET_pin,LOW);
Serial.println(“send VIN for 6 seconds”);
delay(6000);

TaDa:

ReadVINFor6Seconds

The focus is on the reading for Vin between the two readings for Vout.  When the MUX switches to VIN, it takes about 3 seconds for VIN to stabilize.  I’ll add a delay(300); after switching to Vin and discharging the cap.

 

That’s It

What this post is about for me is a better understanding of how to use a scope to get a better peek into what is going on within the innards of the analog part of the circuit.  WHOA!  I am excited to have learned this…hopefully I will start applying my new found debugging/viewing skills and shorten my bumblings when it comes to  debugging what is a mysterious world for me – the analog circuit…

 

Thanks for reading this far.  Please find many things to smile about.

 


Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...

Ladybug Shield Alpha V2 – Testing the pH

26 Thursday Feb 2015

Posted by bitknitting in Ladybug Shield, pH

≈ Leave a comment

Tags

Ladybug Shield, pH

Spoiler alert…wait for it…the pH circuit works!  Talk about exciting.  I truly enjoy learning all the skills and different disciplines that goes into building a working pH sensor…math, science, electronics, designing, laying out, and building a PCB, writing the software,..and most importantly – the people I learn from along the way.

Ladybug Shield V2

Here it is – a thing of beauty – a fully populated Ladybug Shield Alpha V2 hooked into an Arduino:

IMG 3326

 

I got to use my Zallus controlled reflow oven.  I really like the Zallus (toaster) oven controller.  Heck, I really like the idea of popping a PCB in a toaster oven after carefully placing soldering past and SMT parts.  It is so Easy Bake Oven…I can’t help but smile.

The Goal

The goal of this post is to compare the results of pH circuit tests of the Ladybug Shield with those from an Atlas-Scientific EZO pH stamp.

Thanks to Those That Went Before

Thanks to Chris Gammell and his Contextual Electronics courses I was able to get to this point where I have pretty much finished the firmware and hardware design for the pH portion of the Ladybug shield.

Thanks to Ryan @SparkysWidgets for embracing/helping us followers of his minipH open source product and project.  I find it amazing to learn so much from all that he has shared.  My hope is this effort is a positive contribution to the minipH effort.

Open Source

I will be discussing the contents of the Arduino sketches available at this GitHub location.

Calibrate

pH probes lose their vitality over time and eventually need to be replaced.  In the mean time, the slope of the line mapping pH mV to pH value needs to be calibrated.

IdealpHProbeOutput

I use 2 points to determine the slope of the pH mV/pH value line.  The two points come from reading the pH when the probe is in pH 4 and pH 7 calibrated solutions.  The step between pH values for an ideal probe is 59.16mV.

The calibration sketch I used is located at this GitHub location.

When the probe was in pH 4 calibration solution, the reading was 155mV averaged over 11,551 samples with a standard deviation of .49.  When the probe was in pH 7, the reading was -29mV averaged over 3,859 samples with a standard deviation of .40.  

I felt the variability between readings to be smaller than expected.  I don’t have a sound reasoning other than I expected more noise between samples. Maybe < 1standard deviation is what is expected.  The results were expected.

The pH slope = y/x = (155 – -29)/(7-4) = 61.33.

Now when pH values are calculated, a step value of 61.33mV will be used instead of 59.16mV.

Read pH

See the calcpH() function in the Arduino sketch.

(note: I evolved this part from Ryan – SparkysWidgets – minipH.ino.  Thanks Ryan!).   Converting the mV value from the ADC into a pH value involves two steps:

  • compensate for the offset of the pH 7 mV reading of the probe from the ideal of 0 mV
  • figure out how many steps away the mV reading is from pH 7.
Since figuring out how many steps away the mV value is from pH 7 assumes the ideal pH 7 = 0mV, start with adjusting the mV value to compensate for the pH 7 mV value.  From calibration, the mV value for pH 7 for the probe I used was -29mV.
 
When I put the probe into pH 4 calibration solution – this time to read the pH and not calibrate – the mV reading from the ADC was 153mV.  Given the offset, the mV value when pH 7 mV = 0 is 153 – -29 = 153 + 29 = 182.  Calibration provided the probe’s step value at 61.33mV.  The pH value of a 153mV reading given this probe = 7 – 182/61.33 = 4.03.  Wow!  That’s a darn good measurement.

Compare with Atlas-Scientific EZO pH Stamp

 I had an older Atlas-Scientific pH Stamp so I purchased the EZO pH Stamp.  I have to say I am very impressed with it.  With the older pH stamp I had to send a command several times to make sure it pH Stamp reacted.  This was not a challenge with the EZO ph Stamp.  Unpacking the EZO and first use is a pleasurable experience that requires no additional electronic knowledge.  In short, if you want a “high” quality pH sensor that works with an Arduino, the EZO is worth a look.

I compared the readings from the EZO pH Stamp with the Ladybug Shield for two solutions:

  • White distilled vinegar
  • Baking soda added to filtered water
  EZO Ladybug % difference
Vinegar 2.56 2.67 4.21
Baking Soda 7.94 7.85 1.14
 
The difference in readings is acceptable.

What’s Next

Work on the pH measurement circuit and firmware is almost done.  I have learned a lot as I traveled this journey.  From the science and math behind a pH measurement to the electronics used to detect a voltage that can then be interpreted in a pH value.  I got a lot of help from folks like Chris Gammell and Ryan @SparkysWidgets.

I haven’t added temperature adjustment.  I’ll do this in an upcoming post.

 

Thanks for reading this far.  Please find many things to smile about.

 

Share this:

  • Twitter
  • Facebook
  • Reddit
  • Google
  • Email
  • Pinterest

Like this:

Like Loading...
← Older posts
Advertisements

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013

Categories

  • 3D Pringint
  • 433MHZ
  • 802.11
  • A Salad A Day
  • ADC
  • Analog Circuits
  • Arduino
  • Atlas Scientific
  • Audio Recording
  • Base Station
  • BTLE
  • cc3000
  • Cloud Services
  • Conductivity
  • Contextual Electronics
  • Data Logging
  • debugging
  • DHT22
  • Diagnostic Tests
  • doxygen
  • DS18B20
  • EC
  • Eclipse
  • electronics
  • Healthy EC Shield
  • Healthy pH Shield
  • Herbs
  • Home Network
  • Hydroponics
  • indoor gardening
  • JeeLabs
  • Ladybug Blue
  • Ladybug Nutes
  • Ladybug Plant Food Adjuster
  • Ladybug Shield
  • LED
  • Lettuce
  • LTSpice
  • Moteino
  • New Category
  • New Project
  • nRF24L201
  • nRF51822
  • Nutrients
  • Othermill
  • PAR
  • PCB
  • pH
  • PHP
  • power supply
  • Prototypes
    • Building Our First LED Circuit
    • Sending Sensor Data to a Web Server
    • Wireless Communication Between Sensors
  • Readings
  • RFM12B
  • RFM69
  • Schematics and Board Layout
  • sensors
  • sling
  • soldering
  • SparkysWidgets
  • TCS34725
  • temperature
  • thermistor
  • Uncategorized
  • Vegetables
  • virtual ground
  • Voice Recording

Meta

  • Register
  • Log in

Blog at WordPress.com.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
%d bloggers like this: