bitknitting

~ Stuff I Learned About Tech+Hydroponics

bitknitting

Category Archives: sensors

Air Sensor Node

26 Thursday Dec 2013

Posted by bitknitting in 433MHZ, Arduino, DHT22, Moteino, sensors, TCS34725, Wireless Communication Between Sensors

≈ 11 Comments

Tags

arduino, DHT22, Moteino, Sensor Data, TCS34725, wireless

 

I’m separating environmental sampling into two sensor nodes, the air

airair: report on the temperature, humidity, LUX, and color temperature

 

 AirSensorNodeImage  AirNodeFritzingImage


and Water Sensor Node.

waterwater: report on the pH, EC, and water temperature.  Adjust pH and EC to optimize a plant’s intake of nutrients.

 

This post focuses on the air sensor node.  

The Goals

In this post I will:

  • identify and discuss the choice of components for my Air Hydroponics Sensor Node.
  • run the air sensor node through a sample sketch to show its features.

The Air Sensor Node’s Job

The job requirements include:

  • measuring the air temperature, humidity, LUX, and color temperature at the location it is placed. To make the measurements the photo sensors from the light sensor need to be exposed to the light.
  • repeated measurement at a “reasonable” time period.  These measurements will most likely not change much within an hour.  There will be notable differences between readings made in the daytime versus nighttime.  As well as when the grow lights are on and when they are off.  
  • sending the sensor data to the base system.  The data may need to travel through walls and a couple hundred feet.  Although eventually I envision a base system to be collocated with sensor nodes.  

The Parts List

These are the main parts of the node:

Components

Task

DHT22 + 1 10K Resistor

measure Air Temp and Humidity

TCS3472

measure LUX and color temperature

Moteino

read measurements and send to the base system

FTDI Adapter

USB-Serial bridge to load sketches onto the Moteino

Battery (TBD)

provide power for at least one year

5mm RGB LED + 3 330 ohm R

provide feedback on the state of the node

I have discussed the DHT22 and TCS3472 in earlier posts.  Since I come from no understanding of RF options for in-home networks, I explored a variety of options.  Most of which I discuss here.  Based on these explorations, I have chosen the Moteino with the RFM69HW (data sheet for the RFM69HW) to provide wireless communication between the Base System and a Sensor Node.  

The Moteino

Moteino Felix Rusu‘s small business, lowpowerlab.com  created and builds the Moteino. It includes an ATMega328, either an RFM69HW or RFM69W, and optionally a 4Mbit  (512 KByte) flash chip.  The Moteino appears to be an evolution of the JeeNode.  Both have a focus on low power consumption in an effort to minimize the power consumption of the battery. Like JeeLab’s, it has a strong, helpful (and growing) community and excellent support.

The RFM69

I noted above the Moteino comes with either the RFM69W or RFM69HW chip.  The “HW” at the end of RFM69 refers to the chip that boosts the transmit range at the expense of power consumption.  This video provides a good overview of the differences between the two chips as well as the differences with it’s predecessor, the RFM12B.

RFM69HWPins

RFM69HW

While it was not essential why, I was curious why there were two GND pins.  So I asked the element14 community and got what I took as a reasonable explanation.  It greatly helps my understanding of electronics to put a chip design’s feature choice in context.:

From Dave M.:

Usually in a RF module you will find multiple grounds. RF can be very temperamental,  Sometimes the Digital GND and Power GND and RF GND are isolated from each other.  It could be due to a RF noise, it could be that they had an extra pin and decided to use it for GND and not leave it floating. Only the RF Engineer and PWB layout Designer will have that specific answer.  You could experiment and use only one and see if it operates correctly. From a user stand point, tie both to the GND on the Arduino.  Working in the Test Engineering field for over 20 years and working with RF for 30 years now.  More GNDS in RF the better…..

Air Sensor Node’s Job Requirements

In order to perform these jobs, the air sensor must:

  • Run on a battery.  The battery must power the node for a minimum of one year before needing a change.
  • Provide trouble shooting visual clues about the state of the node.  The Node states include:
    • cannot read sensors
    • cannot find the base system
    • working
    • not working
    • low battery 
I rely on the RGB LED blinking a color to figure out what state the node is in.

The Sketch

The Sketch I used for the Air Sensor Node can be found here.  

Pseudocode

I thought it would be easiest to follow the code if I also included pseudocode. 

One Time Setup

  • initialize sensors and wiFi
  • Set the state of the device to WORKING.

Loop

  • If the device is working:
    • (FUTURE) Check to see if the battery level is low.  If it is, give a visual clue through the RGB.
    • Read sensors and send readings to the Base System.  If acceptable readings can’t be made,  set the state to NOT_WORKING_SENSORS.  Give a visual clue if there was an error reading the sensors
    • (FUTURE) Tell the Base System to send a notification/alert  If the air temperature or humidity is above or below what is healthy for the plant.
    • Send the sensor readings to the Base System.  If the Base System could not receive the sensor readings, set the state to DATA_NOT_SENT.  Give a visual clue if there was an error sending data.
    • Give a visual clue if both reading and sending were successful.
  • wait some amount of time before repeating

Reflections

The RFM69 chip is what I am ending up as my RF of choice for in-home networking requirements.  Exploring the other options helped me gain a firmer grasp on communications between a node and a base station.  I come from a software background.  I am getting a better appreciation of the difference between software and hardware prototypes.  The main difference is in cost for parts and debugging.  I order most of the parts.  This adds both a cost for the part and shipping.  Then there is waiting around for the part.  On top of that, the IDE (development environment) is much more rich for software debugging.  While the Arduino IDE and the amazing assortments of libraries available are well done, they do not have the depth and richness I enjoy when programming using Xcode to build iOS apps.  On the other hand, building these sensors is more inspirational to me than building just an iOS app because the sensors solve in home challenges in new ways.

I really like dividing up the nodes into an air and water.    I am excited to get the water node going. I will be automating the feeding of nutrients and pH adjustments above readings and notifications.

While I have learned a lot, I am continually amazed at how much I don’t know.  It certainly motivates me to get up in the morning!

What’s Next

Areas I will be working on include:

  • Minimizing a node’s power consumption (and choice of battery):  I’m just starting to get my head around power consumption.  I will explore ways to figure out the amount of voltage left in a battery as well as minimizing the amount of current used.
  • Eat my own dog food.  I will be using the Air Sensor node on a new hydroponics system I am in the process of building.  I expect to make adjustments to the node as I learn more in day to day usage.
  • Take another pass at the Base System.  This will include adding notifications/alerts (noted above in the pseudocode as FUTURE).
  • Start the Water Sensor Node.  I can’t wait to automate the feeding of nutrients and adjustment of pH!
  • Making a PCB of the node.  I’ve never made a PCB.  After the “dog food” phase, I want to go through the process of using either KiCad or Eagle Cad to create the Gerber files. I also want to figure out the source for parts and the CoGs to make a small batch of PCBs.
I signed up for this course given by Chris Gammel that I think will give me a head start on making the PCB.  I listen to his podcast, The Amp Hour…he seems to know his electronics stuff. I also went through his intro kiCad course and learned a lot.  

Contextual Electronics is set of two 8 week online courses meant to teach you how to build your own hardware. Students will work in groups to design printed circuit boards using the open source CAD program KiCad; in the second half of the course, students will also build the hardware as a community, working to piece together theoretical knowledge and practical application. At the end of the course, students will feel confident taking an idea from concept all the way through to construction of a prototype.

Until next time……
Advertisements

Share this:

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

Like this:

Like Loading...

Hydroponics Sensor Data to Base System then into Excel

29 Friday Nov 2013

Posted by bitknitting in 433MHZ, Arduino, Data Logging, Home Network, sensors, Wireless Communication Between Sensors

≈ Leave a comment

Tags

433MHz, arduino, Data Logging, Google Docs, sensors

This post builds on the content of previous posts as well as what I have picked up from the exceptionally helpful folks that have left comments, replied to questions in a variety of forums, and other helpful folks that have published their findings in their blogs and websites.

Time to Log Data

One of the features of the Base System will be to capture hydroponics sensor readings to a local file so that I can then do whatever post analysis and environmental improvements based on readings that are affecting the plants.  In this post I’ll send data from a Hydroponics Sensor Node to the Base System. The Base System will store the data on an SD card in CSV (Comma Separated Value) format.  

CSVDataFromSensors

I will then open the CSV file in Excel or Google Docs to see if I can notice any trends in the readings or fixes I should make in the pH, amount or kind of nutrients, temperature conditions, and possibly the lighting conditions.

Steps

The steps to do this include:

  •  Sending sensor readings to the Base System.  This was done in an earlier post.  While I look into some SPI misbehaviors, I’m going to use a 433 MHz TX and 433 MHz RX  to talk between the Base System and the hydroponics sensor node.  I’ll start by setting up the sketches using two USB ports on my Mac.  This makes it easier to debug because I can open up two terminal sessions and view the Serial.print() statements.  then move the sensor node to the hydroponics system.
  • Writing data to the SD card in CSV format.
  • Importing CSV file into an Excel spreadsheet.

Parts

  • Two Arduino Unos – one for the Base System and one for the sensor node.  Plus two breadboards, as well as the usual amount of wires to hook the circuits together.
  • 1 433MHz Transceiver and 1 433MHz Receiver
  • 1 SD Shield and SD Card 
  • DHT22 Temperature and Humidity Sensor
  • DS18B20 Water Temperature Sensor
  • Light Sensor
  • pH probe and stamp
  • LCD with an I2C interface to save on the number of pins used (optional but very helpful)

Sketches and Code

You can download the sketches and code used in this post here.   I’ve decided against showing code in a post.  I’d rather have the code be documented enough so that you understand it.   Please let me know if you find stuff you don’t understand.  I’d like to then update the code as needed so that it is easier to use.  Of course, please suggest improvements!  I hate to remind – but my college degrees are in Geology and I spent most of my working life in management.  We can all improve with your help.

Can You Hear Me Now?

This post is focused on getting sensor readings into an analytics tool such as Google Docs and Excel.  I used some inexpensive 433MHz TX/RX components that I had lying around to send and receive the sensor data.  This YouTube video is a great way to jump start using the 433MHz chips if you haven’t already done so.  The sketches use the VirtualWire library.  You might also be interested in the active forum.  The VirtualWire library documentation notes in section 5, performance,: At 2000bps, Range over 150m  (492 ft) [mileage will vary].  My mileage definitely varied.  I saw a much smaller range.  This is most likely due to RF interference in my house.

Back to the 433MHz. I’ll be swapping these out for my “final” home sensor/automation network solution when I choose it.  I hope not to be spending too much additional time on RF exploration.  I’ve learned to a level where I am by no means an expert, but do feel comfortable with how the different RFs work at the level needed to use for a home sensor/automation network.

Goldilocks and the Three RF choices

One of the areas I wished to explore was the varying RFs to make up the home sensor network.  My goals in this exploration include:

  • gaining an understanding and familiarity at the sw/hw level of low cost home sensor/automation network RFs
  • choosing a solution for my hydroponics home sensor/automation system
The features I am looking for in a solution include:
  • low cost
  • “adequate” range (the ability to transmit from anywhere in my house and receive from the point farthest away)
  • robust Arduino software library that has the “right” APIs (“right” is determined by need and seems to vary the more I learn!)
  • low power
  • enthusiastic, helpful internet community
  • includes features such as the ability to determine signal strength, node differentiation such that multiple nodes can transmit sensor data to a Base System and the Base System will know which node sent it, and reception by the Base System of uncorrupted packets within a reasonable timeframe.  There are always going to be dropped or corrupted packets.  How easy is it for the Base System to receive uncorrupted sensor readings? 
  • requires minimal soldering on my part 

Up until now I have been exploring the capabilities of the various RF solutions, the Arduino libraries that come with them, and what level of support is available.  I’ve stayed away from solutions like zigbee and Z-Wave because of cost (true in both cases) or barriers to entry (true in the case of Z-Wave).  For example, I sent a question to the Z-Wave alliance about exploring Z-Wave.  The chairman (Mark Walters) sent the following email:

Getting involved with native Z-Wave development isn’t for the faint of heart.  To develop one must first purchase a developer’s kit from Digikey and in doing so sign a licensee agreement with Sigma Designs the IP holder of the Z-Wave technology.  The least expensive developers kit is $1,500 and then you will need a $3,500 compiler and about $1,500 worth of developers hardware.  I’m not sure if you want or need to go this route.   You mention Arduino, we really don’t have a fully baked Adriano solution but we do have a very good solution for the RasberryPI.  Please take a look at this solution and see if it will work for you.  http://razberry.z-wave.me/  If you are dead set on Adriano then starting with the Z-Way middleware will save you the whole Sigma Designs developers kit step.

Wow!  Too serious of a commitment and way to expensive for me…I have seen this strategy with what I consider low level technologies before.  However, there is an opportunity to become the 802.11 of home automation/sensor networks.  It is not clear to me that just because I can buy products in Staples that use a wireless technology that it will become the dominant standard.  We saw this with TCP/IP (in some ways versus Novell”s IPX/SPX).  The openness of TCP/IP – as well as its ability to work well across routers across long distances – provided an environment where solutions thrived.  Z-Wave’s strategies (and others similar – or others at a higher price point during exploration stages) sadly preclude these technologies.

Which leads me to think of my exploration of RF for home networking as the story of Goldilocks and the three RF frequencies….The first I tried was the nRF24L01.  I found this solution to be unreliable and not well supported or embraced by the community.  Of course, reliability doesn’t improve since I purchased the chips on eBay.  I found the TX/RX to work intermittently.  The software library was not of the ease of use and quality.   Also, it was not obvious how to participate in a community of folks using them.  I would scurry to different forums and websites, with no dominant forum to absorb the findings of the folks that have come before me.  Thus, it was hard for me to ask questions and get timely and to the point responses.  I’m also concerned with this RF using the 2..4GHz frequency.  We have a lot of BlueTooth devices.  Plus a higher frequency will not have as far a range and will also use more power.  I’ve decided against using the nRF24L01 moving forward.

The second RF I tried was the JeeNode from JeeLabs.  There are many things to like about JeeLab’s products.  A LOT of GREAT THINKING went into different aspects – such as power consumption and RF Frequency.  The library is robust.  There is many postings of why different components are used and details on the software library.  The software library is robust.  The JeeLabs forum is active, extremely knowledgable, and helpful.  The challenges I have include I am not bought into the port abstraction for attaching sensors.  It is easier for me to think in terms of the Arduino pins and not a node representation.  I got spoiled by the DHTxx library that was available for the DHT air temperature and humidity sensor.  I wanted such a library for all the sensors.  Alas, not all the sensors use I2C not have as nicely done libraries.  However, the sensors are extremely simple with extremely simple APIs – so not having the simplified   Also, the RFM12B is an old chip that has been replaced.  I would like a chip that I can get from multiple sources and is not generally discontinued.  Yes, Modern Devices can still get chips based on their agreement with Hope RF.  But it is still a chip that the manufacturers no longer wish to produce.

The third is the one I am using for this post, the 433MHz TX/RX components.  These chips are great for initial experimentation because they are extremely simple to use.  There are significant drawbacks as my knowledge improves on indoor RF solutions.  I found the range to be inadequate.  Either due to RF interference or range, there were many times when I was lucky to get one reading after a minute when sending readings every second.  There was one wall and about 50 ft between the transceiver and receiver.  The library is very basic and extremely simple to use.   There is no support for very helpful features like RSSI feedback to help set up the best reception experience.

The most promising looks to be Hope’s replacement for the RFM12B, the RFM69.  LowPowerLabs looks to have promising “kits” that have been built on the shoulders of the great work JeeLabs has done with their JeeNode.

Transmitting Sensor Data

As you can see from the image of the current implementation of a hydroponics sensor node:

 

hydroSensorNode

 

(…I’ve got to start cleaning up the wires, shrinking its size, put it into a waterproof container, and figure out where to put it so that it doesn’t interfere with the plants!  I haven’t done this so far because I am test, adding, and removing parts.  For example, this version includes a 2×16 LCD that is an immense debugging help.)

The Base System will be receiving sensor readings on air temperature, humidity, water temperature, lux, color temperature, and pH.  I’ve discussed each of these in earlier posts.  Currently what is transmitted is “hard coded” such that the Base System is expecting a packet that contains these readings – and no other kind of packet.  In the future, there will be at least one other type of packet – the header packet which tells the Base Station what sensor readings will be sent and in what order.  For now I went for the “quick and dirty” approach to gathering data.  Also in the future I will support multiple nodes.

As shown in SensorNode433.ino:

  • I take a reading every 5 minutes.  Each minute I display the number of minutes that have passed since the last reading on the LCD.Time can be adjusted by changing TIME_INCREMENT_DELAY – the time between updating the number on the LCD and NUM_TIME_INCREMENTS – the number of increments before a reading + 1.  Thus, TIME_INCREMENT_DELAY*(NUM_TIME_INCREMENTS-1) = time between readings.  
  • the first byte sent over is the number of sensor readings that will be sent.   This will be used by BaseSystem433.ino  to determine if all the readings are contained in the received packet.
  • all readings are sent in uint16_t format.  

 

Here is a line of sensor readings:

Sensor

DEC

HEX

Humidity

43

2B

Air Temperature

68F

44

Water Temp

66F

42

Color Temp

5634

1602

LUX

30000

7530

pH

61 (6.1)

3D

The packet sent over the wire is 13 bytes.  The contents of each byte given the sensor readings is:

6

0

2B

0

44

0

43

16

2

75

30

0

3D


Keep in mind that Arduino is little endian.

As I used in previous posts, I will use the:

  • DHT22 for measuring the air temperature and humidity.
  • DS18B20 for measuring the Water Temperature,
  • TCS34725 for measuring the Color Temperature and LUX.
  • Atlas Scientific’s pH Circuit for measuring the pH.
I am not yet comfortable with the pH readings since I do not calibrate as often as I need to.  In the future I will add this functionality using a technique similar to the one shown in the Sparkfun video.

 Since my post on the need to conserve SRAM, I am more conscious of saving SRAM.  I:

  • put the freeRam() function into a library called debugHelpers (TODO: GITHUB LINK) so that I can use this handy function to check the remaining SRAM from within any sketch.
  • started to standardize on using Serial.print(F(” “)); so that debugging strings go into Flash and not SRAM.
  • dropped using the  Dallas Temperature Control Library.  I used the OneWire library instead.  I feel much more comfortable with Arduino programming and always find it best to get rid of abstraction layers when possible.
  • Avoided using String objects.  While the flexibility and additional functionality are useful, as David Crocker points out in his blog post, “Five things I never use in Arduino projects”, using String objects come at the cost of dynamic memory allocation and additional memory overhead.

With all sensor readings except the pH reading, values can be returned as uint16_t.  The pH value is different because at a minimum the first decimal place is needed. The pH reading comes in as a string such as “7.45”.  I convert this to an integer that puts the first decimal place in the single digits space and the integer value(the value before the decimal point) in the tens and hundreds place.  For example, 7.45 becomes the integer value 74.  Doing this makes it easier on sending and receiving the packet at the expense at the “goo” needed to map into pH readings.

I added an LCD monitor to the Hydroponics Sensor Node.  This way I could write debug statements to the LCD while the sensor node was running near the hydroponics station.

Receiving Sensor Data

This configuration of the Base System includes an Arduino Uno, the SD Shield, and the 433MHz transceiver.

BaseSystem

The configuration plus the additional memory used by the BaseSystem.ino sketch left 595 bytes.   I will definitely have to move to an Arduino that has more than 2K SRAM.  The most likely replacement will include the ATmega 1284P.  No longer does the Base System need to feel closed in because of too little SRAM.  The ATmega 1284P has (a whopping compared to the 2K of the ATmega 328P!) 16K of SRAM.

Viewing Sensor Data

There is code in the BaseSystem433 sketch that checks to make sure the readings are valid, creates a string containing the date, time, and sensor readings in CSV format and then stores the string in the datalog.csv file.  Each time the Arduino is reset/starts, the earlier  datalog.csv is replaced with new readings.  Ultimately, deleting the old data is not what I want.  For now it is the easiest.  Since I know how I could implement a better handling of data logging files, I’ll leave that for something to do in the future.  

At this step I can start to analyze the sensor readings in a spreadsheet application.  This image shows a line chart of the readings for the air temperature.  There is a dip during evening hours, especially during the times when the LEDs are off.

ExcelAirTemp

 

While I took a reading every minute, the Base System did not receive all of them so the time between readings varies.  It is good enough for my purposes.   I did have to more the Base System closer to the Hydroponics Sensor Node.  As noted earlier – the 433MHz is not the one I will use in the future for the home sensor/automation network.

I have also included the .csv file in case you are interested in playing around with it.

What’s Next

  • resolve or at least gain a better understanding of the challenges I have had with components not sharing the SPI bus.  From a learning perspective, I will go a little deeper than I probably should because – heck learning is extremely motivating and fun – and it will help me better understand interactions between an Arduino and components. 
  • send the Sensor readings to the Xively service and analyze from “any device.”
  • update what is going on with the hydroponics system. 
  • finalize the home sensor/automation network RF.  
  • finalize the components of the Base System.
  • determine what probe and “stamp” to use in order to help with measuring the amount of nutrients provided to the plant’s roots.

and other things I haven’t thought to list.  

Share this:

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

Like this:

Like Loading...

Better Together? Arduino Uno+SD Shield+cc3000+RFM12B

14 Thursday Nov 2013

Posted by bitknitting in 802.11, cc3000, RFM12B, sensors, Wireless Communication Between Sensors

≈ 2 Comments

Tags

Base System, hydroponics, Sensor Data, wireless

In the last post on the hydroponics sensor network, I detailed using a JeeNode as the wireless micro controller from which sensors would be connected.  Previous to that, I discussed the beginnings of a Base System that was based on an nRF24L01 wireless between a sensor node (not a JeeNode at the time) and Adafruit’s cc3000 (802.11) breakout board. 

I am calling the hardware and software that receives the sensor data – eventually from a number of sensor nodes that are monitoring and applying action from hydroponics systems throughout my house – the Base System.  I am still exploring what hardware features to include.  In this blog post, I am exploring a Base System that uses an Arduino Uno, JeeLab’s RFM12B board to receive data from a JeeNode, Adafruit’s cc3000 breakout board to send the data to an Internet service, and Adafruit’s SD Shield to keep a local store of the sensor data.

Goals

The goals of this post include:

  • Wiring up the components into a circuit that receives data from a JeeNode.
  • Discuss lessons learned.  Fortunately – or unfortunately if you have “been there, done that” since I fear my write up of these will bore you – there are plenty lessons learned since this is the first time I have put these separate components together under one Sketch.
  • Detail two areas of concern: 1) The amount of SRAM gobbled up by each component and 2) How well the components cooperate sending and receiving data over the Arduino’s SPI bus.

Challenges

The third goal makes special note of two areas of concern.  On the one hand, it is amazing how many libraries exist for all these components that “plug and play” with an Arduino.  On the other hand, there is no quality control on the libraries.  There is no mandate that says minimize the amount of SRAM used – even though SRAM on an Arduino is a very constrained resource.  There is no hardware compatibility assurances that make best efforts for components that share a bus to play well together.

For an example of hardware compatibly, take the use of the SPI bus.  A challenge with the SPI bus is summarized as a bullet point under “Disadvantages” in the SPI Wikipedia entry:

Without a formal standard, validating conformance is not possible

Wouldn’t it be great if there was a test harness for components that use the SPI device as there are for devices that are plopped into many operating systems?  Well, there isn’t. 

Steps 

The steps I’m going to take include:

  • Determine the SRAM memory footprint of each of the components to see how much of the 2K SRAM the ATmega 328p has that is being taken up.
  • Replace the JeeLink with the RFM12B board  since the JeeLink is not extensible.
  • Isolate each component with the Arduino and run the component’s “hello world” sketch.
  • Add each component to the Arduino Uno.  As each component is added, run their respective “hello world” sketch that comes with the supporting library.
  • Test if the devices “play well with others”  when they access the SPI bus. 

Amount of SRAM

Before we dive into the components, I wanted to share what I found out about determining the all important amount of available SRAM.

JeeLabs has an excellent post on measuring an ATmega’s memory use.  In addition, the Arduino memory tutorial also has some useful information. His post includes a function that will let me know how much SRAM is being taken up when a component is added.  This will give me an idea if (more likely when!) I will need an ATmega with more SRAM:

int freeRam () {

extern int __heap_start, *__brkval; 
int v; 
return (int) &v – (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

I find the above type of functions clever.  Look at this image
ATMega Memory
and note how the freeRam() function uses the address of v – the last variable put on the stack – to determine the gray area (i.e.: available memory) between the heap and the stack by subtracting the address of the top of the heap from the address of the top of the stack.  

The post also gives additional insight:

all C strings are also stored in SRAM! This explains why adding a single character to the string reduced available memory.

Luckily, the Arduino IDE provides a way to stick strings in Flash – of which the AtMega328P has 32KB:

You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example: Serial.print(F(“Hello World”));

So to minimize the memory use, I put all Serial.print[ln] strings inside an F().

Another thing the IDE lets me do is to store variables in Flash instead of SRAM.  For example, the line char payload[] = “Hello!”; can be put into Flash memory by using the prog_char typedef.  to prog_char payload[] = hello!”;  My thought was every little bit of SRAM counts.  But ultimately, the ATmega 328p will most likely run out of 1K or more of needed memory.  It does seem like good practice until someone with more experience tells me why doing so is a bad idea.

I’ll be using:
  • freeRam()
  • wrapping Serial.print[ln] strings inside an F()
  • storing variables into Flash memory
As I check the amount of SRAM used by each component’s libraries.

Amount of available SRAM

I wanted to follow up on a comment made by Matt:

“… the ATMEGA 328P only has 2K SRAM and if you intend to use SD cards, ethercards and wireless cards in your system, you might find this a limiting factor. You might want to look at maybe using something like an ATMEGA 1284P based system.”

Given the small amount of SRAM, Matt’s concerns are definitely valid.  But do I immediately need to the ATmega 1284P?

Here’s the additional amount of SRAM used by the component’s libraries:

 

bytes

prior to adding components

209

Adafruit’s SD Shield

693

RFM12B board

100

cc3000

590

Total

1592


After the components are piled on, I was left with 456 bytes. A tight fit! I will most likely change fairly soon to an ATmega with more SRAM.

 
Now it’s time to get the components to work.

Testing Each Component

Adafruit’s Data Logging Shield

I got the Data Logging Shield and shield stacking headers for an Arduino Uno from Adafruit.com.  For the SD card I found an old one that was lying around the house used in a now obsolete digital camera many years ago. 

Solder the Headers

I found this post by freetronics to give helpful hints on the best way to solder shield stacking headers onto a shield.

SD Shield Showing Solder Job

I was happy to see that my soldering skills have improved a bit.

Testing the Data Logging Shield

The libraries I used to test the shield included:

  • Adafruit’s SD Library
  • RTC Library

I followed Adafruit’s tutorial to test and become familiar with the shield.  There was a lot at the beginning of the tutorial I ignored because I am using an Uno and these sections were for other Arduino variants.The first thing is to try out the RTC (Real Time Clock).  This was easy and worked great.  It was exciting to read:

 For the RTC library, we’ll be using a fork of JeeLab’s excellent RTC library

within the tutorial.  I truly appreciate the great works that we build upon!  

The tutorial recommends formatting the SD.  This was easy enough using this formatter:

Download the formatter from https://www.sdcard.org/downloads/formatter_4/

I then ran the CardInfo.ino sketch which came with Adafruit’s SD library.  

Yippee!  Here’s what I got on the serial monitor:

______________________________________________________________________

Initializing SD card…
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3644850176
Volume size (Kbytes): 3559424
Volume size (Mbytes): 3476

Files found on the card (name, date and size in bytes

______________________________________________________________________

The first two times I ran CardInfo.ino, I was guilty of two checks noted below: 1) I didn’t insert the SD card 2) I had left the SPI chip select to 4.  I needed to set it to 10.  I found this initial check in the sketch helpful.  Taking debugging one more step, I wish all libraries were capable of providing APIs that debugged more deeply at each level.  During my stint at Microsoft, we realized the layers of interdependency at both the hardware and software level.  A lot of attention was put into making sure the various network stacks (e.g.: TCP/IP, security) had debugging output. It gets extremely time consuming to track down challenges without that.  I feel this is an area where these open source libraries and break out boards could help save us a lot of time.  However, I doubt it will sell more breakout boards.  Plus, I doubt the breakout boards are put in positions that could bring a Fortune 50 company’s network down.   So I can see why the extra effort is not applied to detailed testing and debugging.  

I found CardInfo’s “what might be wrong checklist” to be extremely helpful in debugging the most obvious reasons why the SD card is not read.

______________________________________________________________________

Initializing SD card…initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

______________________________________________________________________

JeeLab’s RFM12B Board

Since the JeeLink does not support adding on additional components, I purchased JeeLab’s RFM12B Board Kit so RFM12B can be added to an Arduino through the SPI bus.  This will allow the base station to gather sensor readings from the JeeNode that was built in this post.

RFM12B Board Kit

The kit comes with all the goodies that need to be soldered together before the breakout board can be attached to an Arduino.  I used the info in this PDF to figure out where/how the resistors, capacitors, antenna, and RFM12B chip should be soldered.

Here is the breakout board after I soldered it together.


 
RFM12B FrontSide
 RFM12B BackSide
 
Clearly my soldering skills need improvement.   I like the way the board has made it easy to remember which pin of the board needs to be wired to which pin on the Arduino (note the D13 above SCK/D12 above SD0, etc.).  I outlined two other boxes which turned out to be trouble spots.  I’ll cover these later.

Can You Hear Me?

Time to test out the RFM12B sending and receiving packets to the JeeNode.  For this test, I uploaded the RF12Demo.ino sketch that is found within the RF12 Examples that come with the JeeLib library onto both the RFM12B board and JeeNode.  The RF12Demo sketch is great for getting a feel for how well communications are working between nodes.  
 
BUMMER…. 😦 ….The RFM12B board did not work.   A Challenge!  Why, why, why?
 
I wrote out how I eventually got the board working because I see debugging as a key part of the process of coming to something that actually works in real life – not just on paper.  Debugging is an amazing learning opportunity.

TroubleShooting

Here is what I get after using the AppleScript to set up two terminal sessions (and changing the serial ports to match those used by the RFM12B and JeeNode)
 
 
RF12Demo First Try
The screen shot is a bit hard to read – on the left is the JeeNode (serial port AE01DTYI).  On the right is the RFM12B board (serial port USBMODEMFD111).  I use the ‘t’ command to (as the help notes) “broadcast max-size test packet, request ack.”).  The JeeNode (left) is working.  But the RF12B board is not.   So I do what I normally do in my troubleshooting process: 1) self-doubt: “gee – the chances of me getting this working is small.  Should I just get another one?” 2) review the RF12Demo.ino sketch and the RF12.cpp library. 3) make sure communications settings are correct.  Are they both at the same frequency?  Are they in the same group?  What are the values for the node?  Originally the RFM12B board was on node 1, group 212, and sending/receiving data at a frequency of 433MHz.  Compare this to the JeeNode which was set at node 31, group 100, 868 MHz frequency.   
 

First Change

The first change I made was to set the node/group/frequency of the RFM12B board.  The RF12Demo.ino supports the serial input commands that are displayed when the ‘?’ command is enterred.  Entering 8b changes the frequency to 868MHz.  Entering 100g changes the group to 100.  Entering 31i changes the node to 31.  
 
Note: from the JeeLab FAQ:

Node ID’s should be unique within the netGroup in which this node is operating. ID 31 is special because it will pick up packets for any node (in the same netGroup). ID 0 is also special, it is used to transmit in a special “OOK” format.

In the future I will use different node id’s between 1 and 30.
 
Did it work?
 
Try again with the settings showing both nodes on the same frequency, within the same group, and on node 31.  Nope…still doesn’t work.
 

Second Change

My next step was to check the wiring.  Was GND and + and SPI pins all connected correctly?

Arduino And RFM12B

Always a good thing to check!  This time I seemed to have wired the pins correctly.

My next step is to cry for help on the JeeLabs support forum.  Once again, the members of this forum are incredibly helpful.  I have also found them to give insightful guidance.

Plutonomore recommended changing the 3v3 connection to 5v.  I did, but I should be able to use either since there is a connecting pin for either 3v3 or 5v (see the image above).

 RE: Trouble Shooting RFM12B Board Kit? – Added by plutonomore 1 day ago

It also just occurred to me that you are using an Arduino, therefore 5V, not a JeeNode 3V3.
Therefore try the previously suggested wiring setup but change the 3V3 connections on both
boards to 5V. Also you will need to have the 3x 4k7 and 3x10k ohm voltage divider resistors

cheers,

Comment
                                  

 JohnO noted the DATAFLASH #define (I agree that my soldering needs practice!).  It turns out the JeeLink and JeeNode have a data flash chip that is used for data logging.  So I took JohnO’s advice and set #define DATAFLASH 0 from #define DATAFLASH 1.  I saved the sketch with this change to RF12DemoUno.ino since now the JeeNode and Arduino UNO + RFM12B are different.  But I am not sure why data logging would get in the way of transmitting and receiving data…

 RE: Trouble Shooting RFM12B Board Kit? – Added by JohnO about 5 hours ago

Your soldering isn’t too bad although Rohan will be appalled – Rohan is Martyn’s son and a wiz with a soldering station.  

If you are happy to, can I ask that you load the RF12Demo while only changing “#define DATAFLASH 0”. With a terminal session connected to both running versions of RF12Demo and capturing output. Then press the ‘?’ once on each and follow up with a second or two of ‘t’ command. Then post the two output files that you captured.

 Did it work?
 Try again with these changes….Nope…still doesn’t work.
 

Third Change

 I had sent a reply that included the images above to show my soldering efforts.  It is not clear to me how to debug which resistor, capicitor, or other component I soldered is not working.  
And then a YIPPEE!!!! Moment when Martynj noted:

 RE: Trouble Shooting RFM12B Board Kit? – Added by martynj about 5 hours ago

Hmmm.. a couple of “dry” joints visible but more significantly, ANT // Vdd on the RFM12B module appear shorted. Worth a touch up with solder braid, but may prove to be terminal.

Take a look at the front and back of the RFM12B images above, focusing on the areas that have the red rectangle on them.  I used solder remover to get rid of excess solder around the antenna.  And then put more solder on pin on the back side of the board.

Solder Remover

I then cleaned off the flux using the inexpensive technique noted in this youtube video.  This technique seemed to work well.

Here is the front and the back of the RFM12B after removing solder around the antenna and adding solder to one of the pins for a resistor:

 Solder Off Ant  SolderOnResistor

 Did it work?

YIPPEE!  This worked. I was surprised.  I assumed I’d muffed up the soldering beyond repair.  Luckily, I had not.


JeeNode

Arduino Uno + RFM12B Board

[RF12demo.10] _ i31 g100 @ 868 MHz

Available commands:

 <nn> i     – set node ID (standard node ids are 1..30)

 <n> b      – set MHz band (4 = 433, 8 = 868, 9 = 915)

 <nnn> g    – set network group (RFM12 only allows 212, 0 = any)

 <n> c      – set collect mode (advanced, normally 0)

 t          – broadcast max-size test packet, request ack

 …,<nn> a – send data packet to node <nn>, request ack

 …,<nn> s – send data packet to node <nn>, no ack

 <n> l      – turn activity LED on PB1 on or off

 <n> q      – set quiet mode (1 = don’t report bad packets)

 <n> x      – set reporting format (0 = decimal, 1 = hex)

 123 z      – total power down, needs a reset to start up again

Remote control commands:

 <hchi>,<hclo>,<addr>,<cmd> f     – FS20 command (868 MHz)

 <addr>,<dev>,<on> k              – KAKU command (433 MHz)

Current configuration:

_ i31 g100 @ 868 MHz

OK 63 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

-> ack

OK 63 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

-> ack

> 0t

test 0

-> 66 b

OK 223

> 0t

test 1

-> 66 b

OK 223

[RF12demo.10] _ i31 g100 @ 868 MHz

Available commands:

 <nn> i     – set node ID (standard node ids are 1..30)

 <n> b      – set MHz band (4 = 433, 8 = 868, 9 = 915)

 <nnn> g    – set network group (RFM12 only allows 212, 0 = any)

 <n> c      – set collect mode (advanced, normally 0)

 t          – broadcast max-size test packet, request ack

 …,<nn> a – send data packet to node <nn>, request ack

 …,<nn> s – send data packet to node <nn>, no ack

 <n> l      – turn activity LED on PB1 on or off

 <n> q      – set quiet mode (1 = don’t report bad packets)

 <n> x      – set reporting format (0 = decimal, 1 = hex)

 123 z      – total power down, needs a reset to start up again

Remote control commands:

 <hchi>,<hclo>,<addr>,<cmd> f     – FS20 command (868 MHz)

 <addr>,<dev>,<on> k              – KAKU command (433 MHz)

Current configuration:

_ i31 g100 @ 868 MHz

> 0t

test 0

-> 66 b

OK 223

> 0t

test 1

-> 66 b

OK 223

OK 63 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

-> ack

OK 63 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

-> ack

 
The commands I typed in don’t show up.  But it is easy to walk through.  The cell on the right represents the serial output of the sketch running on the Arduino Uno + RFM12B Board.  The cell on the right is output from the JeeNode.  I typed t as input to the sketch running on the Arduino Uno..  This wrote “>0t ->66 b OK 223” out to the serial port from the sketch running on the Arduino Uno.  On the left, the JeeNode received the data.  The sketch on the JeeNode wrote “OK 63 0 1 2 3 4 5….” to the serial port.  I type t twice to the Arduino Uno and twice to the JeeNode.
 
One more YIPPEE! because it was an amazing experience to “fix” this challenge!
 

Adafruit’s cc3000 Breakout Board

I’ve gone through testing the cc3000 in a previous post, so I won’t repeat the process here. 

Better Together?

Add the RFM12B to the Data Logging Shield

Time to find out if the RFM12B can ping/pong within the same sketch the SD Shield is spewing out info about the SD card.  This will test how well the components share the SPI bus.

Here’s where I ran into my first challenge.  Both the SD shield and the RFM12B board used pin 10 for the SPI CS (Chip Select).  Luckily, the RFM12B’s library has been enhanced to include rf12_set_cs() .   I set the CS pin for the RFM12B board to 9.  Although this solves my challenge of using two different pins for the two SPI CS pins, I was curious how easy it was to change the CS pin used by the SD Shield.  I asked how to do this on the Adafruit forum.  Here’s the answer I got.

Postby adafruit_support_bill » 08 Nov 2013 17:58

Yes. You can cut the trace between pin 10 and the adjacent breakout hole. Then you can run a jumper from the hole labeled “CS” to any other pin.

Image

 I didn’t try this – but good to know….

 

Sketch for JeeNode

Here is the sketch I downloaded onto the JeeNode:

 

#include <JeeLib.h>

 

MilliTimer sendTimer;

prog_char  payload[] = “Hello!”;

//char  payload[] = “Hello!”;

 

void setup () {

  Serial.begin(57600);

  rf12_initialize(2, RF12_915MHZ, 33);

}

void loop () {

  if (rf12_recvDone() && rf12_crc == 0) {

    Serial.println(F(“Receive data”));

    for (byte i = 0; i < rf12_len; ++i)

      Serial.print(rf12_data[i]);

    Serial.println();

  }

  if (sendTimer.poll(3000) && rf12_canSend()) {

    Serial.println(F(“Send data”));

    rf12_sendStart(0, payload, sizeof payload);

  }

}

Sketch for Base System

Note within this sketch:

  • The RFM12B CS pin is set to 9 right before the call to rf12_initialize().
  • The SD Shield library and pieces of the CardInfo sketch have been added so that data will have to flow between the components and the Arduino.

#include <JeeLib.h>

 // include the SD library:

#include <SPI.h>

#include <SD.h>

// set up variables using the SD utility library functions:

Sd2Card card;

SdVolume volume;

SdFile root;

// change this to match your SD shield or module;

const int chipSelect = 10;   

 

MilliTimer sendTimer;

prog_char  payload[] = “Hello!”;

//char  payload[] = “Hello!”;

 

void setup () {

  Serial.begin(57600);

  rf12_set_cs(9);

  rf12_initialize(1, RF12_915MHZ, 33);

   pinMode(SS, OUTPUT);

  // we’ll use the initialization code from the utility libraries

  // since we’re just testing if the card is working!

  while (!card.init(SPI_HALF_SPEED, chipSelect)) {

    Serial.println(“initialization failed. Things to check:”);

    Serial.println(“* is a card is inserted?”);

    Serial.println(“* Is your wiring correct?”);

    Serial.println(“* did you change the chipSelect pin to match your shield or module?”);

  } 

  

  // print the type of card

  Serial.print(“\nCard type: “);

  switch(card.type()) {

    case SD_CARD_TYPE_SD1:

      Serial.println(“SD1”);

      break;

    case SD_CARD_TYPE_SD2:

      Serial.println(“SD2”);

      break;

    case SD_CARD_TYPE_SDHC:

      Serial.println(“SDHC”);

      break;

    default:

      Serial.println(“Unknown”);

  }

void loop () {

  if (rf12_recvDone() && rf12_crc == 0) {

    Serial.println(F(“Receive data”));

    for (byte i = 0; i < rf12_len; ++i)

      Serial.print(rf12_data[i]);

    Serial.println();

  }

 

  if (sendTimer.poll(3000) && rf12_canSend()) {

    Serial.println(F(“Send data”));

    rf12_sendStart(0, payload, sizeof payload);

  }

}

 

YIPPEE!  I got the following output on my terminal windows when I ran these sketches:

Base System Serial Output

JeeNode Serial Output

Card type: SDHC

Receive data

72101108108111330

Send data

Receive data

72101108108111330

Send data

Receive data

Send data

Receive data

72101108108111330

Send data

Receive data

72101108108111330

Send data

Receive data

 

Note on the serial output for the Base Station there is info coming from both the SD Shield and the RFM12B.

SPI Misbehaving – Add the cc3000 to the SD Shield and RFM12B

I set the CS pin for the cc3000 to pin 8.  Now the SD Shield uses pin 10 for its CS, the RFM12B uses pin 9, and the cc3000 uses pin 8. 

So what happens when I put the components that share the SPI bus – the RFM12B board, SD Shield, and cc3000 – in the same sketch?  All is fine when the SD Card and the RFM12B board share the card.  Unfortunately, when I added in the cc3000, the Base System could no longer receive data.  

Drat… back to the Adafruit forum to see if I could get help troubleshooting.

Postby ktownsend » 05 Nov 2013 18:08

I really don’t know what this could be off the top of my head.
The TI modules do use a less common SPI mode (most devices use Mode 0). Alternatively, perhaps when the interrupt fires on the TI the CS lines on the TI side asserts at the same time that the CS line on the other module is asserted, so both devices are listening and everything goes off into the weeds?
The best solution would be to hook up a logic analyzer if you have one (Saleae Logic, etc.) and see if both CS lines at some point are asserted, just as somewhere to start?
Kevin

and

Postby adafruit » 06 Nov 2013 01:37

the breakout version of the cc3000 needs something to buffer MISO as it is not tristated
http://learn.adafruit.com/adafruit-cc30 … onnections
you can look at the cc3000+SD example sketches for how to share the SPI lines, but no, the CC3000 does not work great with other SPI devices without a lot of care & debugging. this kind of stuff is not easy to fix, if you’re “new to electronics”, you may find this project challenging and we don’t offer coding or library modification support and assistance.
our suggestion is to find an RF module that does not require sharing those pins. 

There was another thread in the forum that discussed other issues (and refers to the cc3000’s use of SPI mode 1):

by adafruit_support_rick » 23 Aug 2013 18:56

SD sets up the SPI control register once when you call begin(), and expects it to be correct forever after. Well-behaved SPI drivers should save SPCR, reconfigure it for their own purposes, and then restore SPCR on the way out.

Postby toegap » 27 Aug 2013 04:32

You are right about the SPCR. That needs be different for each of the libraries. If both libraries are set to SPI_CLOCK_DIV2, the only difference is that cc3000 uses SPI.setDataMode(SPI_MODE1) while sdfat(sd card) uses SPI.setDataMode(SPI_MODE0). Both of these effect the state of the SPCR variable. So you need to toggle the SPCR back and forth when you are using these libraries.

hmmmm….if anyone reading this has any suggestions – Please leave a comment.

Next Steps

 I want to complete the Base System.  I’ll look at the best options for: 1) wireless between nodes 2) Internet connectivity to send/receive from the Internet and 3) data logging.   I’ll also delve a bit more into the SPI challenge/conflicts noted above.  It looks like a good opportunity to learn!

Until next time…

 

Share this:

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

Like this:

Like Loading...

My Indoor Veggies – Entry 2

24 Thursday Oct 2013

Posted by bitknitting in Building Our First LED Circuit, Home Network, Hydroponics, JeeLabs, LED, sensors, Vegetables

≈ Leave a comment

Tags

home sensor network, hydroponics, LED

This post goes over first go-round of a hydroponics system that is using a DIY LED setup.

I started with a basic DWC system in our basement that used one T5 bulb for lighting.

DIYDWCSystem

As noted in this post, the LUX was 9950.  I started measuring the  KWH with a Kill-A-Watt and found the TD5  bulb used 1.15 KWH.  The PAR value was 100 µmol photons m2s-1

The T5 provided 9950 LUX.  It will be interesting to see how the LED system compares relative to its PAR and LUX values.

Since then, I have found that I am lazier than I thought.  I want the plants within an area I frequent regularly.  That would be the kitchen.  Many years ago we redid our kitchen to include an eating area with a big round table which has hand, footprints, and drawings done by our kids when they were little.  Luckily we love our home with no plans of selling.   We had plants surrounding the area behind the seats.  Unfortunately, our two cats delighted in using the dirt as a cat box so we removed the plants and covered it up.  I’ve decided to reopen this area to a hydroponics system that surrounds the back.  What is nice about the hydroponics system is it is all water.  I can keep the cats out of the system, and I’ll figure out how to keep one of them from eating the leaves and puking them up.  He likes to do that.  

Since I like to get hands-on, I’ll be adding and adjusting constantly as I explore the “best” way to grow vegetables that we can pick to make a fresh salad or have a snack.

My initial start is what I refer to as my “Basic Hydroponics System.”  Disclaimer: I am just starting on my journey into hydroponics.  I do not claim my setup would work well for anyone else.  I am hoping it provides some knowledge to a fellow n00b and hopefully those more versed in this area will let me know what could be better.

The Base of my Hydroponics System

I’m going to start by growing tomatoes, cucumbers, spinach, and dwarf sugar snap peas.  I picked these because they are some of my favorite vegetables.  They also struck me as a fairly diverse group.  I thought a diverse group would give me a wider range of results given my early stages in hydroponics using LEDs as the light source.

To start with, my indoor garden includes two 5 gallon buckets purchased from Lowes each for under $3. I also got two bucket lids  at $1.28 each.  

In one I put a 6″ net pot.  I bought a 10 pack for $21.  Assuming I’ll use them all, the one 6″ net pot cost $2.10.  I put three 3 inch net pots in the other bucket.  The 3 inch net pots cost $6.50 for 1 dozen.  THe cost for three was $1.63.  I got a pump + hose + airstone from petco for $13.  I filled the net pots with ““Easy Green Hydroton Growing Media, 10 Liter Bag” ”  (aerated clay pellets).  The bag cost around $25 making me think there must be a less expensive alternative – like gravel or something that people try to get rid of.  Something I need to look into.

I put a  rock wool cube ($12.84 for a pack of 45 – $.29 each).  There are other options that might be better such as perlite or coir.  Another area where I need to know more about.  I chose rock wool because it was used in the DIY article I started with. 

What About the Temperature?

Water Temperature

 
I wasn’t sure what water temperature would work best for the vegetables.  Google searches (at least with the search terms I was using) did not lead to any additional knowledge, so I asked the question on the hydro subreddit and got this information:
______________________________________________________________________________________

[–]ElWaffles 4 points 1 day ago

Ideal water temp should be 68 up to like 72. 80f is no good for holding oxygen.

 

[–]thewsPlant Eater 2 points 1 day ago

For water you normally want to keep it under 72F no matter what if you can.

Air temps don’t matter as much, but they can’t stand full sun and temps in the summer (90F+ heat). Of course they don’t like under 40F temps very much either, and they don’t do very well with short days (supplemental light if in a greenhouse in the winter).

 

–]Potatonet 1 point 14 hours ago

Hi,

During veg to early fruit set: 70-78 During mid-late fruiting: 75- low eighties

The tomatoes need the heat for proper sugar conversion and flavor, especially in a hydro situation, no one likes a water ball.

 

[–]squarepush3r 0 points 1 day

air temperature range ideally 55-80 range

water temp from 55-80 as well

____________________________________________________________________________________________________

 

 Given these answers, my current thoughts is to keep the water at about 72F/22C.  Before I automate and to compare the sensors that are used to hand held units, I also got a digital thermometer.  The current temperature of the water is 62F/17C.  Since this is a little lower than I want, I went ahead and ordered two submersible heaters whose temperatures can be adjusted.
 

Air Temperature 

The Dance Between PAR and Air Temperature

 
I just read an interesting research paper (Tomato quality is more dependent on temperature than on photosynthetically active radiation) that concluded air temperature is more important than a higher PAR value.   This image is interesting.  The researchers plotted the different quality characteristics of a tomato relative to a Control group (where Control means 100% PAR values).  The 70% and 50% PAR values reference the samples that were considered in shade.  What is shown here is the tomatoes in the shade did not have readings that were very different from those in the sun.  
 
Sun Ray 1
SSC can be interpreted as sugar content.  The sweeter the better! 
 
Based on the results summarized in the above image, the report concludes “…growers in our region could obtain tomatoes of similar quality under lower PAR than natural sunlight.
 
Now that PAR value has been discounted, the researchers looked at tomato qualities based on temperature ranges.  850C is the cumulative degrees measured over 45 days.  Dividing the numbers by 45, 850C = 18.8C/66F and 1000C = 22.22C/72F
 
Sun Ray 2
 The paper notes (wow! learning new words like organoleptic!) Regarding organoleptic properties, all parameters showed slightly lower values at the lowest T cum  interval  (T cum < 850◦ C) (Fig. 7). It was concluded that daily T cum has an effect on tomato quality, with lower values of T cum leading to higher and lower values of antioxidant and organoleptic properties respectively.  They seemed to discount the variation in Vitamin C based on a comparison of mixed results by other researchers.  Having my background in science leads me to think any of these results can be reasonably disputed but they are a stepping stone to a great knowledge of how temperature and PAR values effect tomatoes during their flowering stage.
 
Although they found yield had a quite different outcome.  Lowering the PAR value by 30% from sunlight decreased the yield by 14.3% and a 50% lowering decreased the yield by 38.1%.  Also, fruit size decreased as the PAR value lowered to 50% of sunlight.
 
I have found over the years that there is research can’t help itself but by being subjective.  It is not the data, however the interpretation.  With that said, as I build up my knowledge base, I’ll follow some of the findings.  I view the settings of the hydroponic system(s) as an iterative process.
 
Thus based on the results of this article and given I am mostly interested on the organoleptic 🙂 qualities, as with the water temperature, I will maintain a constant 72F air temperature using the space heater noted earlier in the CoGs for the base system.  The space heater will be too small as the amount of plants grow. For now I’ll be able to gauge results on a smaller amount of plants at the lowest possible cost.
 
I will not raise the PAR values for this setup.  I will do another LED setup that emits higher PAR values.

The Food

 

To start out with, I am using Dyna-Gro – Grow 7-9-5 Plant Food.  I chose it because It was recommended on a DIY Hydroponics blog posting, it got good reviews on Amazon.com (note to self: be more skeptical about reviews!), and it advertises itself as a nutrient supplier that spanned the vegetation and flowering cycles. I’ll see how well it works and then change as I see what works and learn from others.  

_____________________________________________________________________

Note:

The 7-9-5 refers to the percentage of Nitrogen-Phosphorous-Potassium.  I’ll most likely change the nutrient mix once I evolve my learning on the appropriate nutrients for the plant and plant cycle.

 

 A thread on the hydro subreddit had some advice on what this expert uses:

_____________________________________________________________________

uranium_hexanitrate 3 points 7 hours ago

Start with clarifying your NPK: 13-11-9. You want the nitrogen for vegetative growth, and while 13 is a bit on the low side, it’s certainly more than adequate. Many people will use a balanced fertilizer (10-10-10 or 20-20-20) and still get good results, so super-high nitrogen need not be applied.

Back off on nitrogen and up the phosphorus and potassium for blooming. Peppers aren’t picky; you can probably make do with the same formulation all the way.

_________________________________________________________________________________

As noted here:

“In hydroponics, the plant roots are constantly provided with all the water, oxygen and nutrients they need….As a general rule, a plant consumes more nitrogen during the formative or vegetative stage, and more phosphorus, potassium and magnesium as it flowers. Throughout its growth cycle, the plant will also consume calcium, sulfur and micro nutrients such as iron, manganese, boron, molybdenum and copper.”    

Nutrients

(image from here)

_____________________________________________________________________ 

 

Measuring nutrient levels

There are two measurements that are important to stay on top of – the pH value and theEC/TDS/PPM  value of the water the plant roots call home.

Measuring PPM

I bought this inexpensive TDS Tester.  It seems to work pretty well.  Also, it seemed that several on the hydro subreddit used this tester with success.  The first reading I got before adding Dyna-Gro was 50 ppm.  I added 100ml to each 5 gallon bucket.  The new ppm reading is 1540 ppm.  According to the information found here, 1540 ppm seems like an acceptable value.  Like everything else, I’ll adjust as I learn more. 

Measuring pH

Maintaining the right pH level is important to how well the plant can absorb nutrients.  I found this image to be helpful:

PH Values

 

I used a PH Meter to measure the pH.  It turns out the pH was too basic at 7.  I ordered General Hydroponics pH Down to get the pH around 6.  (FOLLOW UP: Do NOT use this pH meter! I discuss this in an “Indoor Garden Report.”

There are many different products that can be used to measure the pH value.

 

Pieces of the Base System

 

 Lowes Bucket  LowesLid  RockWoolCube  NetPot  ClayPellets  Digital Thermometer  WarmWave Space Heater  dyna grow nutrients TDS EZ  PH Down  3 in 1 meter

Bucket

Lid

Rockwool cube

Net pots

Clay pellets

Submersible thermometer   Space Heater Nutrients  TDS Tester  pH Down  pH meter

 

 Cost of Goods

All dollar amounts are pre-tax.

Shared

  •  Space Heater:   $12.97 
  • Plant Food: $18.33   
  • TDS Tester: $15.59 
  • PH Meter: $12.57 

Per System

 
 

 

1 6” Net Pot

3 3” Net Pots

Bucket

$2.78

$2.78

Bucket Lid

$1.29

$1.29

Net Pot(s)

$2.10

$1.63

Rock wool

$0.29

$0.87

Clay pellets

$1.55

$0.72

Air pump, etc.

$12.99

$12.99

Submersible Heater

$18.28

$18.28

Total

$39.28

$38.56

 

The LED Setup

I went over the components I would use in my first LED system in this post.  My husband and his friend built me a fixture from sheet metal they had lying around then mounted the CPU heat sinks on the fixture.  I put one LED array (cool white) on one heat sink and the other warm white on the other heat sink.

I set up this LED circuit:

2LEDCircuit 2

 
 

 

 

 LDDCircuit  power supply  LEDs  LEDsOnPlants  Crimp On Spades  CPUFan
 
I used spade terminals to attach the wires to the power supply.  I got these at Home Depot.  The smallest amount I could be in this size and type was 75 for $6.97.   I used 5.  Plenty more are left for future projects.
 
As the hours past, the heat sinks rose to a temperature in the mid-90F.  The steel plates got into the mid-80’sF.  I mounted each LED on a CPU cooler.  These acted as very nice heat sinks.  They both have a fan.  So I powered them up with a 12V wall wart.
 

How Much Light is Enough? 

superAngryGuy had a great posting in the hydro subreddit on the amount of LUX a plant should get:

15000-20000 lux____ the lower end of what we want for veg growth

35000-40000 lux____ what we want to try to hit for flowering

75000 or so lux_____ it’s pointless to go beyond this level of light intensity, saturation level
 
 During this past summer, I measured the outdoor PAR value in mid-August on a day that had a few puffy clouds as well as the PAR value for the T5 light I had previously been using.  The measurements were:

Outside – Sun

1865 µmolphotonsm2s-1

Outside – Shade

170µmol photons m2s-1

T5

100µmol photons m2s-1

 
 

 1 Bucket PAR and LUC  3 Bucket LUX and PAR
 
 
 
 
I was going to add an Arduino + RF so that I could control the PWM/DIM in order to lower the brightness of the light.  This is easy to do since as you can see in the image each LDD has a DIM pin.   For now I’ll stay with what I have here and won’t use a dimmer since full daylight lux is around 10,000 – 25,000 LUX and direct sunlight is between 32,000 and 130,000 LUX.  Although both superAngryGuy’s and the wikipedia entry on LUX point to direct sunlight for flowering tomatoes. 
 
Given the outside sun PAR value, I am concerned the PAR values on the plants are too low.  They are however much higher than outside-shade and the T5.   Down the road I’m sure I’ll be adjusting the LED setup.
 

 

 

Cost of Goods

I did not provide a CoGs for the LED system in my post “Introducing the  Components of the First LED Circuit.”   So I’ll provide one here:
 
 

CXA2520-0000-00N00Q450F-ND

$15.30

CXA2520-0000-00N00Q20E8-ND

$16.60

2 CPU Coolers

$13.98

2 WM9779 CREE CXA25 LED Holder

$6.44

Meanwell s-250-48 Power Supply

$45.00

2 Meanwell LDD-1000Hw LED Driver

$14.66

Spade terminals

$0.45

Timer

$12.32

Total

$124.75

 
 I could have used an Arduino for the timer but felt using a wall plug-in timer is a simpler and less expensive way to go.  Also, the Power Supply and timer can be used for additional LED set ups so the cost of adding more will be less than this initial cost (up to a point).
 

What’s Next?

I’ll be updating this post with weekly updates.  My next step is to focus on what I want to be notified and automated using an Arduino and RF – which right now I have moved on from nRF24 to JeeNodes in my exploration of RFs for home sensor networks.  More on that in the next post. 

 

submer

Share this:

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

Like this:

Like Loading...

Part 3: Adding Sensors With a Focus on the Properties of the Light Readings

10 Thursday Oct 2013

Posted by bitknitting in Arduino, LED, nRF24L201, sensors, TCS34725

≈ Leave a comment

Tags

Adafruit, arduino, DHT22, LED, nrfL2401, Prototypes, sensors, TCS34725

From now on I’ll refer to the Arduino + sensors + RF (i.e.: no 802.11 connectivity) as the Sensors Node.

This post is a follow-on to the posts:

  • Wiring Together the 802.11 Chip And nRF24L01 Chip
  • Transmitting Data from One nRF24L01 to the Other using One Mac

Sensors for Plant Growth

The sensors I want to have on a Sensors node for my hydroponicsproject include:

  • air temperature
  • water temperature
  • humidity
  • LUX
  • Color Temperature
  • PAR (Photosynthetically Active Radiation)
  • pH
  • TDS (Total Dissolved Solids)
Each of these sensors will provide valuable information that will help me grow delicious fruits and vegetables.  This post focuses on sensors for (air) temperature, humidity, and light characteristics.
 
Light sensing is given the most attention because the measuring and calculations are more complex than those for sensing humidity and temperature.  Perhaps the reason for this is my lack of context regarding key concepts of light characteristics.  For those that are experts in this area I have a favor to ask.  Can you please correct any information you read is incorrect or…it would be great if you could enhance understanding of this amazing and rich topic (light characteristics)?
 
After publishing this post, a member of the hydro subreddit forum  made a comment that got me thinking about what sensors the Sensor node really needs for day to day operation versus setup and maintenance.  I will ignore maintenance for now (usually a bad thing to do…?) and focus on day to day operations.  I really only need to know the color temperature, LUX, and PAR value for setup.  These are important – and worthy of more exploration, but I would rarely raise an event or be interested in the day-to-day change UNLESS the Color Temperature, LUX, or PAR changed dramatically.  I see the light being ON as the most significant event.  More common than drastic changes in LUX, Color Temperature, or PAR.  Moving forward I will use a very simple and inexpensive photoresistor.
CDSCell
Examples of Photoresistors
 

Sensor for Temperature and Humidity

I’m using the DHT22 temperature-humidity sensor from Adafruit.  This seems to be a popular sensor for measuring temperature and humidity through an Arduino.  Not surprising, Adafruit has an easy to follow tutorial on using the sensor.

humidity-temperature-sensor-dht22-500x500

The DHT22 is simple to use.  Check out Adafruit’s wiring diagram. It is so easy I’ll leave the wiring up to you.

Sensor for Light Characteristics

Because my journey is to enhance my family’s food with fresh fruits and vegetables grown indoors, I am interested in measuring light characteristics as they relate to plant growth. I chose Adafruit’s TCS34725 color sensor breakout board because it provides not only the LUX value of the light source but also the color temperature.  I was hoping to also get the PAR value – a more interesting light characteristic than LUX values for plants given the photosynthesis process of plants.

TCS34725-800x800While this chip returns RGB values, alas – RGB values cannot be reliably converted into PAR values.

I did find options for PAR measurements:

  • A DIY PAR implementation for $70.  This is a “stand alone” meter built by what I perceive as a very sharp person.
  • The SQ-225: Amplified 0-5 Volt Electric Calibration Quantum Sensor from Apogee for $189.  Angry_Ohm mentioned this option.
I ended up purchasing the DIY PAR meter.  As noted earlier, I don’t need a sensor for each sensor node.  Rather a PAR reading during initial setup and occasional check-up.
 
According to Apogee’s excellent technical support, the SQ-225 seems very simple to use with an Arduino.  The sensor has 3 wires. The white goes to 5V, black to GND, and green to an analog pin.

I2C to Communicate

For many of you, all the delightful ways for chips to communicate with an Arduino are well known.  Being new to it all, I like to briefly look at the pros and cons when I start using a new way to communicate over a bus.  Unlike the nRF24L01 which used the  SPI to communicate with the Arduino or the DHT22 which uses a digital pin, the TCS34725 uses the I2C.

This section of The Arduino Cookbook has a clear explanation of the scenarios in which it might be more beneficial to use one over the other communication bus implementations:

“I2C has the advantage that it only needs two signal connections to Arduino—using multiple devices on the two connections is fairly easy, and you get acknowledgment that signals have been correctly received. The disadvantages are that the data rate is slower than SPI and data can only be traveling in one direction at a time, lowering the data rate even more if two-way communication is needed….

The advantages of SPI are that it runs at a higher data rate, and it has separate input and output connections, so it can send and receive at the same time. It uses one additional line per device to select the active device, so more connections are required if you have many devices to connect.”

As with the other breakout boards I’ve purchased from Adafruit, the TCS34725’s is very easy to wire up to the Arduino.  This tutorial does an excellent job helping you wire up and test the chip. There is no reason to repeat it, so go for it if you are following along.  I wired the LED pin to GND to turn off the LED that is on the chip.

Integration Time and Gain – Setup Variables

Perhaps many of you run across adjusting the integration time and gain in other projects.  I find how folks word a sentence and how I interpret the same sentence can drastically vary. So I wanted to understand the ramifications of these two parameters.

Integration Time

I noticed  when the TCS34725 is being initialized, the amount of integration time and gain can be set.  As noted in Adafruit’s library reference for the Adafruit_TCS34725 library,

“Longer integration times can be used for increased sensitivity at low light levels.“

As adafruit_support_bill notes in an answer to my question in the adafruit forum about Table 6. RGBC Timing Register in the TCS34725 data sheet:

…It is pretty much the same as camera exposure time. This can help in low-light. It can also make a difference with non-constant sources like fluorescents. You need to integrate over some number of 60Hz cycles to get an accurate average measurement. The term “count” in the context of sensors usually means the raw ADC output. I would interpret “MAX COUNT” to be the full-scale reading for the specified integration cycle setting I set the integration time to 700 ms with the intent of optimizing for sensitivity since speed is not a concern.

Gain

Most of you have most likely run across adjusting the gain in your other projects.  I have both in low light photography and also voice recording.  Still – after years of making assumptions I knew what something was and then finding out I did not have the right meaning, I asked what the meaning of gain on the adafruit forum.  adafruit_support_bill was quick to respond (another shout out to Adafruit.  The folks that work there care and are knowledgable.  I find myself buying more and more of my exploration hardware from them.  They seem to truly try to make sure we have a great experience with their products) with:

“Gain amplifies the signal so it is in the range where the A/D converter can measure it with reasonable resolution.  Yes, noise is amplified too.  But without gain, you would not be able to distinguish some signals from noise.”

Bill also noted:

The 3.8 million-to-one dynamic range of the sensor means that measurements at the lower end of that range would only be using 1 or 2 bits of the A/D resolution.

(the 3.8 number is found in the TCS34725 data sheet, page 1 – under features)

Given we’re looking at lights on and not dim lighting conditions, using gain is not a concern.  I set the gain at 1X.

Light Readings

The table below shows five different light setups.  I measured the LUX for each using the TCS34725 light sensor as well as a  LX1010B Light Meter .  I also recorded the Color Temperature readings gathered from the TCS34725.

LightA LightB LightC LightD LightE
Light A Light B Light C Light D Light E

Light A is early morning light that I have the pleasure of observing from my desktop.

Light B is a “natural light” CF reading lamp.

Light C is an AeroGrow 3.

Light D is a T5 above my DIY DWC hydroponic system.

Light E is the “warm white” CREE LED array that is part of the LED system I was building in this post.  A “warm white” color temperature look yellow-orangish.  I got readings of around 2150.  This particular LED array is specified to be 2,500.  “Warm white” helps achieve a more abundant amount of veggies and fruits because it enhances the flowering stage of plant growth.  Why aren’t these values exactly the same?  I assume for a variety of differences used in measurement – differences in temperature, calibration (or lack of in the case of the TCS34725), precision of measurement, algorithm(s) used to calculate the Color Temperature, and most likely others I can’t think of.  I feel the Color Temperature readings from TCS34725 are “good enough” for now.  They are in the ball park that are needed for optimizing flowering of plants. Yet I do not have enough information to say anything about whether this particular led array has or does not have a Color Temperature of 2,500.

  Light A Light B Light C Light D Light E
TCS34725 – Color Temperature 4487 4990 5185 7570 2150
TCS34725 – LUX 20 5660 7100 18500 10700
LX1010B – LUX 14 2820 3800 9950 6500

The LUX readings differ on an average of 1:1.76, with the TCS34725 always giving the larger readings.  This different strikes me as too different to ignore.  Yet they are probably explained by a lack of calibration of either the Light Meter or TCS34725.  So do I calibrate and if so – what should I use?

When I have questions such as this I have a tendency to reach out to the super sharp and helpful folks that make up the hydro subreddit.  My favorite answers tend to come from superangryguy.  I was not disappointed this time with superangryguy’s comment on calibration:

“Calibration of light meters is tricky. My spectrometer costs $250 to calibrate with a NIST traceable standard and to buy a calibration light source is $500-600 and above. I then calibrate everything to my spectrometer.  The diffusion disk should be a cosine correction piece. Most all light meters have either a flat or round white piece of plastic depending on the sensor characteristic and placement. Different sensors can also have different spectral responses. I know of no cheap way to accurately calibrate these sensors or meters. I would try to calibrate the TCS34725 sensor to the LX1010B meter with the sensor and meter directly facing the light source. I’d also use a 5000-6000k (day light neutral) white light source.  The problem here is that you want a true broad band light source. CFLs, for example, have sharp spectral spike as does the TCS34725’s response curves. This is why lights such as halogens are used in calibration. I’d use a blue “cooling” filter to try to flatten the halogen’s light curve. You’d need to look up the spectral response of the halogen then pick up the appropriate gel filter at a photography pro shop. If you go to a pro shop, someone may be able to pick out the right filter gel for you. Glazer’s in Seattle would be an example of a photo pro shop that has a wide range of gel filters in stock. Look at page 6 of the sensor data sheet and you’ll see that the different diodes have different spectral sensitivity and they’re pretty narrow. The clear diode appears to be a normal silicon photo diode judging from its response curve. It does appear to be close to cosine correct. http://www.adafruit.com/datasheets/TCS34725.pdf“

As pointed out by adafruit_support_bill:

“Like all sensors, there is variability between units and they need to be calibrated against a standard. But there are other factors that can account for the discrepancy. These sensors both measure incident light, but the LX1010B has a large diffusing disc in front of the sensor. This will alter the effective angular responsivity of the sensor. They may also be differences in the spectral response of the two sensors. These are documented for the TCS34725 here: http://www.adafruit.com/datasheets/TCS34725.pdf.”

For now I’m going to move on and accept the readings of the TCS34725 without adjustments.  Right now I want to explore and get to a reasonable understanding of challenges that would need further investigation if more precision is required.

Next up: exploring signal strength of the nRF24L01’s.  On the good and bad news front – my cc3000 has decided not to play anymore.  Adafruit is sending me a replacement. Once I get that, I’ll be sending the data from the Sensor Nodes to the PHP service.

I also want to try out the JeeNode and JeeLink I recently purchased after becoming an avid follower of JeeLabs.

Share this:

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

Like this:

Like Loading...
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

Create a free website or 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.
Cancel
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: