Phi-shield revised and released

phi-3-shield-on-in-hand

It has been a while since I gave the phi-shield a major revision. I’ve been working on this for a while and now I am releasing the Phi-3 shield. This shield continues to support user interaction with LCDs and buttons. Here is a list of the features:

The following hardware are provided by the shield:

  • 20X4 LCD with back light on/off control
  • Six buttons (up/down/left/right/B/A)
  • Two LED indicators
  • Speaker
  • MicroSD card slot
  • Real-time clock (DS3231)
  • EEPROM (32KB 24LC256)
  • Connector for Adafruit Ultimate GPS module or Bluetooth module
  • Stacking headers for easy access to all pins.
  • Recessed board right edge for easy access to MEGA’s 18X2 pin headers on the right side.
  • Reset button

phi-3-shield-lcd-side-by-side

The following software functions are provided by various supporting libraries:

  • User-selectable menu (LCD + buttons)
  • Number and text entry (LCD + buttons)
  • Scrollable long text (LCD + buttons)
  • Date and time (DS3231 or GPS)
  • Location (GPS)
  • Data and configuration storage (MicroSD card and EEPROM)
  • Playing simple tones (speaker)
  • Indicators (LEDs)
  • Wireless connection (Bluetooth module)

phi-3-shield-lcd-removed-annotated

There are three tiers of Phi-3 shield kits: kit0, kit1, and kit2, none of which includes a GPS module. The kits are immediately available. Buttons with color caps as pictured will be included while supplies last.

Here is the Phi-3 shield’s own page. There are links on the page to make purchases. Or you can visit the BUY page to see what stores carry this shield.

Phi-3 shield

Video demonstrations will be available next week. Meanwhile, the support of Phi-2 shield will remain. If you need Phi-2 shields, I have them available.

phi-3-shield-bottom-rtc-lcd-wire-removed

Phi-2 20X4 shield kits

This kit is nearly sold out. Due to Chinese New Year, all re-ordered boards and components are expecting long delays. If Inmojo.com and my paypal sales buttons indicate the kits are sold out, then the kits are indeed sold out. Please be patient and check back in a week or so. Sorry for the inconvenience.

SDI-12 concurrent measurement

If you have a few SDI-12 sensors and want to quickly read their values, you may need to perform concurrent measurement. In regular measurement, using an M command, your logger issues the M command and expects the sensor to respond with the number of seconds to wait until data are ready and the total number of values. Here is an example. Assume sensor address is 1. Green is logger and blue is sensor:

1M!

10054\r\n

1\r\n

As you see, the sensor 1 needs 005 seconds to perform the measurement, which returns 4 values. Only the sensor needs to send carriage return (\r) and new line (\n). If the sensor finishes measurement before 5 second expires, it issues a service request, i.e.  its address 1 and carriage return and new line. The logger will respond by asking for data once it receives the service request.

Once the service request is received, or the expected 5 seconds elapses, the logger will ask for data using a D0 command, i.e. D and zero. The sensor will respond with data:

1D0!

1+12.34+56.78-90.12+34.56\r\n

If you have multiple sensors, you need to repeat the process multiple times, waiting about 5 seconds for each sensor. That is a lot of time. If your sensor supports concurrent measurement, you can shorten your wait time to only 5 seconds instead of 5*(number of sensor) seconds. Here is the process using concurrent command C, assuming 5 sensors:

1C!

100504\r\n

2C!

200504\r\n

3C!

300504\r\n

4C!

400504\r\n

5C!

500504\r\n

There won’t be any service request issued and the logger can go ahead to talk with the next sensor as soon as the current sensor responds with number of seconds to wait and number of data points 04 it will return. Notice that the last TWO digits now indicate the number of data points it will return, not the single last digit.

Now the logger proceeds to wait for 5 seconds and then start asking for data the same way it does when it used M command:

1D0!

1+12.34+56.78-90.12+34.56\r\n

2D0!

2+12.34+56.78-90.12+34.56\r\n

3D0!

3+12.34+56.78-90.12+34.56\r\n

4D0!

4+12.34+56.78-90.12+34.56\r\n

5D0!

5+12.34+56.78-90.12+34.56\r\n

Since all sensors are taking measurement almost simultaneously, you don’t have to wait for them individually, saving a lot of time.

Don’t stop here. Sometimes concurrent measurement is SLOWER than reading one sensor at a time! This only applies to faster sensors, such as Decagon 5TM soil temperature and volumetric water content sensor. It reports that it needs 1 second but it requires significantly less than 1 second. So if you use concurrent measurement, you will be forced to wait for a whole second. SDI-12 sensors are intended to be low-power but not for speed. The 1200 baud rate translates into about 120 characters per second, shared between the logger and sensor. The time to send the commands and data back and forth between a single sensor and the logger could take half a second to do!

Procedure to produce small batches of devices

Over the past years, I’ve designed and built devices in small batches such as 10-25 units at a time. I’ve gained some experience doing such small builds. The following is a procedure for building a small batch SDI-12 + Analog USB devices.

The device has a USB serial converter IC FT232RL, an MCU ATMEGA328P (same as Arduino Uno’s MCU), an ADS1115 16-bit analog-to-digital converter, precision resistors, fuse, screw terminal blocks, jumpers etc.

I build the device first by reflow soldering the surface components, and then hand solder the thru-hole components once I’m done confirming the reflow soldered components are working. You’ll see why these devices can’t be sold at $4 a piece, not just because the components cost more from legitimate vendors such as digikey, Mouser, Newark, etc. Most of the steps can’t be completed by someone without proper training of what the device does.

Here it goes. Any recommendation? Post a response!

Manufacturing and inspection procedure

Date: 2016-11-23

1.    Preparation and printing solder paste:

  1. Remove solder paste from refrigerator and set it in room temperature for one hour.
  2. Clean board with alcohol and lint-free wipe.
  3. Visually inspect board for defects and reject boards with visual defects.
  4. Align board with stencil.
  5. Print solder paste.
  6. Check registration especially for ADC, MCU and FTDI chips. Reprint in case registration is too far off.
  7. Wash and dry stencil.
  8. Return solder paste to refrigerator.

 

2.    Components placement:

  1. Place MCU. Check alignment with 3X loupe.
  2. Place FTDI chip. Check alignment with 3X or 10X loupe.
  3. Place ADC. Check alignment with 10X loupe.
  4. Place (5) 100nF caps.
  5. Place (1) 10uF cap.
  6. Place (2) 22pF caps.
  7. Place (1) fuse.
  8. Place (1) EMI bead.
  9. Place (3) 10K resistors.
  10. Place (1) 100K resistor.
  11. Place (4) 1K precision resistors.
  12. Place (4) 10K precision resistors.
  13. Place (1) crystal.
  14. Place (1) mini-USB connector.
  15. Check resistor values with loupe. Replace wrong resistors.

 

3.    Reflow soldering:

  1. Place boards on reflow over racks.
  2. Attach thermal couple to a plated hole on one board.
  3. Turn on temperature gauge.
  4. Connector reflow oven to power.
  5. Follow reflow specifics, make sure to time each step with stopwatches. STOP if expected temperature is not reached within expected time.
  6. Disconnect reflow over from power.
  7. Remove boards and cool them off.

 

4.    Visual inspection:

  1. Visually check for solder issues on chip resistors, caps and other components.
  2. Check for solder bridges on ICs with a 10X loupe.
  3. Check USB connector for bridges.

Found any issues?

  • Y: fix with flux paste, solder braid, and iron
  • N: proceed

 

5.    Flash firmware:

  1. Connector programmer to PC.
  2. Place board on pogo pins.

Programmer detected board?

  • Y: flash firmware

MCU detected after flash?

  • Y: proceed
  • N: check soldering near XTAL pins
  • N: inspect MCU for solder issues and other issues (IC in wrong orientation etc.). Add flux paste and reflow pins.

 

6.    USB connection and initial ADC check:

  1. Connect board to PC.

USB port detected?

  • Y: proceed

Device responding to ID command?

  • Y: proceed
  • N: check MCU and FTDI chip for solder issues

Device returning analog measurements?

  • Y: proceed
  • N: check ADC and MCU I2C pins for solder issues
  • N: inspect connector and FTDI chip for solder issues

 

7.    Check ADC and resistors:

  1. Solder headers and connectors.
  2. Connect different resisters to analog pins.
  3. Set HIGH jumpers on all channels.
  4. Read single-ended inputs.

Results are as expected?

Command ‘zI!’ should return ‘z13Liudr   SDITRD130\r\n’. Command ‘zM!’ should return ‘z0014\r\nz\r\n’. Then command ‘zD0!’ should return ‘z+0.xxxxx+0.xxxxx+0.xxxxx+0.xxxxx ‘ where x is arbitrary but the first x in each number is unlikely going to change if you poll again. Command ‘zM1!’ should return ‘z0012\r\nz\r\n’. Then command ‘zD0!’ should return ‘z+0.000xx+0.000xx ‘ where x is arbitrary and positive signs may be negative signs at times but both values should be very small with at least 3 zeros after decimal.

  • Y: proceed
  • N: check resistors and ADC for solder issue

 

  1. Set LOW jumpers on all channels.
  2. Read single-ended inputs.

Results are as expected?

  • Y: proceed
  • N: check resistors and ADC for solder issue

 

8.    Check SDI-12 bus:

  1. Connect SDI-12 sensor to one SDI-12 terminal.
  2. Poll SDI-12 sensor.

Does sensor return values?

Command ‘1M!’ should return ‘10012\r\n1\r\n’ Then command ‘1D0!’ should return ‘1+1.xx+2x.x’ where x is arbitrary but unlikely to change if you poll again. The second number is temperature so indoor reading should be above 20.0 C.

  • Y: Device passed QC test J
  • N: check MCU SDI-12 bus pin for solder issues

Teaser photo

What can this new board do?

2016-11-22-11-08-48

Guesses? Comments? Answer revealed after US Thanksgiving holiday (2016-11-24)!

(There is nothing on the back side)

SDI-12 bus scan code

In case you need to diagnose your SDI-12 data logger, I posted SDI-12 bus scan code for the SDI-12 USB adapter (in Python) and for the SDI-12 data logging shield (in C for Arduino). Their links are under Data logger programs or Downloads.

Here is a screen shot of the Python code:

bus-scanner

The Arduino code has a similar interface without the serial port select (you select Arduino serial port in Arduino serial monitor). It’s fun translating C code into Python. C is famous for manipulating strings as arrays of ASCII characters. Doing such in Python seems like a hassle because it has no pointer mechanism, loose types, and aims to handle Unicode so it buries the ASCII characters under layers of things. Anyway, each language has its own strengths and weaknesses.

Notice that the scanner shows a Decagon 5TM sensor at address ‘1’ and also shows the SDU-12 translator at address ‘z’. Make sure that each sensor already has a unique address before scanning the bus. To configure sensors with unique addresses, run the configuration code for either the SDI-12 USB adapter or the SDI-12 data logging shield. Hope this helps. Comments?

Arduino Nano for battery-powered projects

Since Arduino Nano is very small in size and cheap, it might be a good choice for a battery-powered project.
Clones are abundant on ebay and other websites for around 4USD and mostly come with CH340 series USB/TTL adapter, instead of the original FT232.

To see how effective it is as a battery-powered platform, I made some measurements and would like to share my results.

First, to save power, you will need a boost converter (or DC-DC converter) instead of using siz AA batteries or 9V batteries on VIN pin. The on-board converter is a 1117-5.0 linear regulator that is not very efficient. I recommend something like this:

https://www.sparkfun.com/products/10968

You can also find some similar boost converters on ebay for less.

You can use two AA batteries to power the converter and get 5V output. Supply it to 5V on Nano. I measured currents on the battery side (@3V), not the 5V side, since I was trying to estimate battery life. I also measured currents on the USB side in case I use a power bank.

When Arduino is sleeping with POWER_DOWN sleep mode, the whole board consumes 15.5mA @3V from the battery. If you are using USB to power it (say you use a power bank), it consumes about 18.5mA. This is definitely not good enough for batteries. Even with a gigantic 20,000mAh power bank, the maximal time is 45 days. The efficiency of the boost converter and activities (other than sleeping) will reduce this to just a handful of days.

Next, the power indicator LED consumes a lot of current, if you want to use batteries, such as two AA batteries. You will need to remove the chip resistor next to it.

My clone has a 1kohm resistor in series with the LED. Once removed, the consumption went down from 15.5mA to 8.8mA (@3V). The resistor I removed was the 3rd one from the right side of the white reset button:


This is 50% saving, which is good and easy to do. You just hold your iron on the chip resistor until it is hot enough to remove it. Having a pair of tweezers helps a lot. Your project may now last weeks on two AA batteries.

After this, you will have to remove the 1117-5.0 regulator to get more power saving. This step is difficult. I used a hot air rework station to carefully heat up the regulator and removed it with only a little damage on the male headers’ plastics. If you don’t plan on putting the regulator back, get a small flush wire cutter and just cut out the regulator at the pins. This should do:

https://www.sparkfun.com/products/11952

The wide tab might be difficult to cut but once you cut the three small pins, you can just hold your iron on the wide tab and remove it.

Once removed with the Arduino put to sleep, only 0.74mA of current is consumed at 3V on the battery. This will project into months of operation, if you are logging data at moderate rate.

So if some of you thinks this is not really what a “pico” processor promises, then I am sorry to tell you that the Nano just wasn’t designed for battery operation. The CH340 consumes a certain amount of power even when sleeping. About 0.15mA at 5V so it could translate to 0.25mA at 3V. Its pull-up and pull-down resistors also cost similar amount of current draw. There is no way to remove the CH340 chip and still use the USB port. Using an arduino mini will solve this problem since it has no USB chip.

On a data logger I designed around ATMEGA1284P, I used FT232 but it will not receive power from the battery. The power consumption is about 0.4mA when sleeping. Not as low as it can go but good enough for 6 months.

So the conclusion is to at least remove the LED’s resistor if not 1117-5.0 regulator as well. If you want to use AA batteries etc. get a boost converter.

Then, if you have other devices, such as sd card, rtc, sensors, you need to power them with a transistor so you can but their powers when arduino goes to sleep.

Hope this helps. I’ll write about parasitic power and how you eliminate it another day.

How Arduino bootloader works

atmega328P_bootloader

Everyone that uses Arduino can tell you how easy it is to get projects going once they have an Arduino board in hand. Just load up the blink code and press upload. In a matter of seconds, your Arduino LED is blinking ever so confidently. But do you stop and wonder how Arduino receives the blink code? Enter Arduino bootloader. Every Arduino has a bootloader, a small program that is always stored on the Arduino to update the code in the Arduino. It only runs once per reset. It looks for new code to be loaded to the Arduino before starting the existing code.

The bootloader works like this:

On the PC side, to trigger a reset on the RESET pin, the PC (avrdude.exe or GNU/Linux equivalent) opens the serial port to Arduino when your press upload and the code is ready to upload. This causes the Data Transmit Ready (DTR) line of the USB/TTL chip to go LOW. The Arduino board has a capacitor charging circuit that uses this LOW (charging the capacitor) signal to momentarily pull down the RESET line of the ATMEGA328P chip before returning it to HIGH (capacitor charging completes). So Arduino resets each time its serial port is opened.

Upon reset, Arduino enters the bootloader.

The bootloader looks at the source that caused the reset. There are several sources that can cause a reset. If the reset was caused by the RESET pin, then it waits for one second for the PC to send in commands. When it receives valid commands, it will start accepting new Arduino code in HEX format and erase the existing code to load new one. If it doesn’t receive valid commands, it times out after one second and triggers a Watch Dog Timer (WDT) reset.

Once the bootloader runs again it will look at the source of the reset. Once it determines that it was the WDT reset, it immediately jumps to the first line of the actual code. This way if you power up Arduino, it will be able to immediately run your code, instead of waiting in the bootloader to time out 1 second. It’s pretty smart!

The optiboot bootloader is the most recent bootloader used by Arduino UNO, nano, and other boards based on ATMEGA328P and 1284P. It accepts commands or uploads code at 115,200, unlike the previous bootloader that accepts commands or uploads code at 57,600. A number of people have modified this standard bootloader to fit their own needs, such as slower upload speed for a bare-bone system with no crystals and runs at say 100KHz on internal RC oscillator to preserve battery. Others have made Ethernet upload possible. I’ve personally made a bootloader that will refuse to upload code unless a certain EEPROM byte is set to a certain value. This way if the device is a data logger and to be used by a student, the teacher won’t be worried that the student would get “smart” and erase the code. But when the teacher wants to change the code he/she can enter a password in the existing data logger program and unlock the device for upload again.

If you want to deploy a project, such as an artistic installation or a data logger, you can make a bare-bone system without the whole Arduino UNO board. Then you will need an ATMEGA328P chip with preloaded bootloader like this one, and some extra components.

Anyway, if your code doesn’t need to be changed any further, you can decide to get rid of the bootloader altogether. On an Arduino UNO, this will free up 512 bytes of FLASH and the end user of your device won’t have the danger of erasing the code. To load code without a bootloader, you can use Nick Gammon’s HEX uploader. All you need is another Arduino UNO and an SD card (shield format is preferred) and some jumper wires.

SDI-12 USB adapter

After some delay, the SDI-12 USB adapter is finally here:

2015-10-03 16.16.57

This adapter is extremely easy to use. Just connect it to your PC and SDI-12 sensor. Then you can use any serial monitor or terminal emulator program to talk with your sensor. Just open the serial port at 9600 Baud rate. You can start by sending device identification command such as ?!. You will see a response from your sensor, which is the one-character address of your sensor. If you have not set its address, it is most likely to be zero (0). Then you can use 0I! to find out the manufacture and model of your sensor, before getting measurements from it. Getting measurement is easy as pie. First send 0M!, then wait for response. Then send 0D0! to fetch the measurements.

For PC users, I even wrote a data logger script that can automatically log data using the popular Tera Term program. You can choose sensor address, total number of data points, delay between points, and time zone when logging, then the program will keep logging data. The following is a screen grab of Tera Term. The sensor is a Decagon 5TM soil temperature and moisture sensor. The address is one (1) and the returned values are relative dielectric permittivity and then temperature in Celsius.

Data logger

Once you get data logging going, you can import the .CSV file into your Excel and plot it. You can choose a proper refresh rate so your data and plot are up to date when you look at them.

Plot

I’m still ordering more circuit boards but should be able to sell these on my inmojo.com store starting now. There is even a quantity discount if you need 10 or more.

Inmojo store sales page

Arduino board install problems

Arduino board is darn close to plug and play. However, there are many arduino compatible boards that come with different USB chips, making the play part just a bit further away from the plug part. So, if you have got your new arduino (or compatible), how do you install the USB chip driver? The following are the steps to identify what driver you need, where to find them, and how to install them.

There are several USB chips different Arduino compatible boards use. An incomplete list of them is supplied at the end of the post.

First of all, if you have good eye sights, you should locate the USB chip on your arduino, which is usually near the USB socket, read its markings. Then find the driver from the list at the end of the post.

On Linux, many of these drivers are included in the distribution so you don’t notice anything except that you now have a new serial port, such as TTYUSB0. On windows, however, you need more work to get the driver installed.

If you are using windows, and you can’t determine (markings too faint) what chip set you have, do the following after plugging in your arduino board:

Go to device manager and find the device with an exclamation mark under “Other devices” as an “Unknown device” (mine actually is already recognized as COM47, yeah, lots of Arduinos).

unknown device

Select properties and view the Details tab. Select under Property “Hardware Ids”. Look at the value.

USB serial port propertiesMine has VID=0403 and PID=6001. It is the FTDI FT232RL. This tells me that I would need the FTDI driver in case the driver is not already installed.

Install the correct driver, remove the arduino, reinsert it and wait for the driver to properly associate with the board. In case that didn’t happen automatically, you want to then right click the unknown device and update driver, then choose “browse my computer”. Then point to the right driver location. This step is necessary for all ATMEGAXXuX chips. The driver is in Arduino IDE under Drivers folder.

Update software driver

The following is a working list of chips, VID, PID and download links. I don’t guarantee the links are current or virus free but I did post official links.

Chip VID PID Board Link Note
Atmel ATMEGA16U2 2341 003D 003F 0042 0043 0044 ADK, DUE, MEGA2560 R3, UNO R3, ADK R3, clones Included in Arduino software under drivers
Atmel ATMEGA32U4 2341 8036 etc. Leonardo, micro, clones Included in Arduino software under drivers
FTDI FT232RL 0403 6001 Nano, Duemilanove, MEGA, clones http://www.ftdichip.com/Drivers/VCP.htm Included in Arduino software under drivers. Many fakes exist so avoid buying cheap Arduino compatible board with this chip.
WCH CH34X 1A86 5523 7523 etc. Many clone boards http://www.wch.cn/download/CH341SER_ZIP.html Supports win 10. Seems best choice for Arduino compatible boards.
Prolific PL2303 10CE Many clone boards http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41 The company claims that many older PL2303 models on the market are fakes so it has stopped supplying drivers for win 7 and up on these models.
Silicon Labs CP210X 11F6 Many clone boards https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx The driver may not work with win 10 so if you just upgraded to win 10 and your board stops working, …

 

%d bloggers like this: