Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Sunday, November 20, 2016

IPv6, Arduino, and temperature

Referring to what I learned last time, I installed the SparkFun library for the HTU21D. Then I did a simple mash-up of MiniHTTPServer and SparkFun_HTU21D_Demo, and it worked on the first try. I think I spent so much time starting two years ago being frustrated with the uIP library that I guess I don't expect Arduino to be simple, or even to work. However, I can now read temperature and humidity over IPv6 for around $25 from eBay, now that I found a working IPv6 (single-stack) library in EtherSia. I'm not complaining, but it just feels anticlimactic after all those months of arguing with the first Ethernet library to have the second Ethernet library work right away with minimal effort.

Lesson (re)learned: Always use the right tool for the job.

For future reference, this sketch would not work with an Arduino with less memory than the Nano v3; it needs that 2kB of SRAM. My hardware is HTU21D for temperature and humidity, NanoShield and EtherSia for IPv6 Ethernet, and Arduino Nano v3.

My code with EtherSia_ENC28J60:
Sketch uses 12,162 bytes (39%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,263 bytes (61%) of dynamic memory, leaving 785 bytes for local variables. Maximum is 2,048 bytes.

My code, but claiming EtherSia_W5100:
Sketch uses 11,864 bytes (38%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,259 bytes (61%) of dynamic memory, leaving 789 bytes for local variables. Maximum is 2,048 bytes.

SparkFun_HTU21D_Demo:
Sketch uses 5,656 bytes (18%) of program storage space. Maximum is 30,720 bytes.
Global variables use 460 bytes (22%) of dynamic memory, leaving 1,588 bytes for local variables. Maximum is 2,048 bytes.

Packet Printer (EtherSia_ENC28J60):
Sketch uses 7,406 bytes (24%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,053 bytes (51%) of dynamic memory, leaving 995 bytes for local variables. Maximum is 2,048 bytes.

Mini HTTP Server (EtherSia_W5100):
Sketch uses 8,112 bytes (26%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,025 bytes (50%) of dynamic memory, leaving 1,023 bytes for local variables. Maximum is 2,048 bytes.

Saturday, November 19, 2016

Arduino Nano with IPv6

I haven't touched my Arduino Nanos in a while because they didn't do IPv6 with the arduino_uip library I thought would work. However, I poked around again, and found EtherSia, so I thought I would give it a try. In the intervening time, I have switched from Mac to Linux for my daily driver.

I went to the Arduino Getting Started page, and downloaded the latest version of the IDE for Linux. I connected my Nano v3 that has the FTDI controller, so I selected Tools (menu) > Board > Arduino Nano and Tools > Port > /dev/ttyUSB0. The software selected Tools > Processor > ATmega328 automatically (which is correct for the Nano v3, but not what the hardware-specific page says to expect). I selected the "Blink" sketch (the hardware equivalent of "Hello, World!", from File (menu) > Examples > 01.Basics > Blink), clicked on Verify, clicked on Upload, and my Arduino Nano is blinking at me.

The relevant output line from lsusb for me was:

Bus 003 Device 047: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

When I run Tools > Get Board Info, I get
BN: Unknown board
VID: 0403
PID: 6001
SN: Upload any sketch to obtain it

No drivers were downloaded; it just worked. Despite knowing that I should quit while I'm ahead (so I can have dinner at a reasonable time), I wanted to try IPv6 from EtherSia! I went to Sketch (menu) > Include Library > Manage Libraries. I put "ethersia" in the Search box, it showed up, I clicked on Install next to the (most recent) version number, and that was just too easy. File > Examples > EtherSia > Minimal. I knew I would want it, so I brought up Tools > Serial Monitor as well. I switched it to 38400 baud (as mentioned in the sketch), and again it just works! I could even ping6 it!

Now I just need to see how it feels about reporting temperature and humidity from HTU21D over IPv6 into my monitoring. That can wait until after dinner!

Friday, January 23, 2015

Nano Drivers

Today's Arduino lesson is that not all Arduino Nano v3 boards are the same (and this is probably true for other Arduino models when purchased from different sources). Let's skip over how long it took me to discover that, m'kay? I discovered this by looking in System Information, going to System Report, and looking at what was connected to USB. Get drivers for that, whatever it is.

My first Nano required PL2303 serial drivers. My second Nano needs the more standard FTDI libraries instead. Sparkfun has FTDI installation directions, and those drivers can also be downloaded directly from FTDI.

And just like that, sprinkling a little driver magic over it, this Arduino is now happy to talk to its IDE. Just as readily, all of the peripherals are now also working with the example code.

Thursday, December 4, 2014

Bumps on the Arduino

So it hasn't been smooth sailing since I installed the Arduino libraries. This is why I was taking baby steps.

I followed the Adafruit directions for the HTU21D temperature and humidity sensor, and got ... nothing. Really nothing. One of my desperate ideas was to look for other libraries. I found SparkFun's HTU21D library, complete with a tutorial. The difference between the two libraries is that SparkFun has two error codes, 998 if sensor is not detected, and 999 if CRC is bad. I saw a whole lot of 998, and that was very helpful. No one likes to hit an error condition, but do you know what's worse? An error condition without an error message somewhere! I removed the Ethernet shield from the system. I ran Blink again just to be sure of my baseline. I ran a lot of continuity tests. (Tip: I always need at least one multimeter with the audible continuity feature.) I read the example code comment "use inline 330 ohm resistor if your board is 5V" and added resistors because my Nano is a 5V board. (Sadly, I didn't have any 330Ω resistors in my supplies. I did have a bag of 120Ω resistors from a long time ago, to use as signal terminators.) I ran even more continuity tests. I checked the 3V3 output voltage (3.28V) and the data line resistances (both about 360Ω). I think it's a dead sensor, possibly zotted before I added the inline resistors.

So, on to the ENC28J60 Ethernet shield for Nano. Again, the sample code didn't work. I tried EchoServer and TcpServer. I modified the example code to use a valid legacy IPv4 address (I decided the first test could be IPv4, even if my end goal is not to use legacy) on my home network, but I couldn't ping it, and I couldn't telnet to port 1000 on it. Additionally, my router didn't have a complete entry for it in its ARP table. Also, the link lights on the shield were off far more often than on. I ended up re-cabling everything in my computer room, both to simplify cables and connections, and to move the little unmanaged switch for extra ports to my desk so I could watch its blinking lights as well. Based on the indicators (no link lights on the ethernet shield, no link lights on the little switch, and no ARP entry on the router), I have to think this one is also dead. However, I also need to test this suggestion before giving up.

Yes, I think it's rather odd that two out of three components aren't working, and the two peripherals at that. It's possible that I need to work on some intermediate steps, to learn more about Arduino. Gee, more tinkering ...

Monday, November 24, 2014

Arduino Libraries

Update 2016-11-21: Since this post has many views, I want to point out that Arduino libraries are easier to install since IDE 1.6.2 (see these directions), and that EtherSia is my Arduino Ethernet library of choice because it supports IPv6 (single-stack) as well as the ENC28J60, W5500, and W5100 Ethernet controllers, and it's simple to change the Chip Select pin.

The next baby step with my Arduino is to load libraries into the IDE. (Yes, baby steps. It's easier for me to do in a short time that isn't as busy, and it's less likely that I'll get frustrated.) The directions to load Arduino libraries look easy enough. (Adafruit, Installing a Library on Mac OS X)

The library for the HTU21D is linked with the directions, another easy step.

And then, despite trying to keep it simple, I thought that first library was so easy, let me add the library for the ENC28J60 Ethernet. Alas, that was a rabbit hole! Here is my saga.

ENC28J60 and Arduino: a history, with an eye to IPv6 support

My journey starts here with Reflective Heat:

The official Arduino Ethernet Shield is based on the WizNet 5100 chip, which implements the IPv4 protocol stack in silicon. As a consequence, the Arduino Ethernet Shield cannot be used to implement an IPv6 stack.

Most people use the ENC28J60 in place of the WizNet 5100, either for its low cost, or because I wanted IPv6 support. And now I step through a littered history.

EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE, from Jean-Claude Wippler. Adapted and extended from code written by Guido Socher and Pascal Stang ... but I don't see IPv6!

Back to Reflective Heat. The RHT IPv6 library for Arduino is based on the work of Pascal Stang, Xing Yu, and Guido Socher for EtherShield and IPv6EtherShield from Günther Hoelzl. And I note:

The earlier ipv6ethershield developed by Guenther Hoelzl was tested but found to be unstable and would not compile on the most recent versions of the Arduino Integrated Development Environment (IDE).
However, I'm a bit nervous about the RHT offering because it only discusses Arduino UNO and Mega, and I have the Nano. So I thought I'd keep looking. Apparently I don't know enough to stay away from rabbit holes!

Hey, I found a list of Arduino IPv6 library choices and Telecom Bretagne is newer! but I don't want a wireless sensor network because wireless isn't as reliable as wired Ethernet. There are directions but for wireless, so I continue to look.

I found a blog with a whole category for Arduino and this Ethernet! but no IPv6 when I searched the blog.

So once again, I found myself back at the beginning, reading about Contiki's μIPv6 stack ported for 1-wire (original site appears to be offline now), but wrong microcontroller and wrong sensor family. However, μIP will appear again, with better luck next time.

The first two libraries at Tweaking4All also lack visible IPv6 support, but discuss the same problem of having a Nano instead of an UNO or a Mega (same concern I had with RHT!). The first set is ETHER_28J60 + EtherShield (from Jose Muanis Castro; mentioned by RHT); the second one is EtherCard (mentioned above). However, the third library looks like a winner! Do I see a nod to μIP? ... drumroll please ...

UIPEthernet has some IPv6! although with a gotcha noted. But I'm reminding myself that my small goal tonight is to load libraries, just the libraries, and not to discover what might be broken later. There are examples to test first!

There are some posts about which CS (chip select) pin to use for various configurations. I like this post because it shows where to change the underlying code if you don't want to re-wire.

Tuesday, November 18, 2014

Getting Started with Arduino

After my first attempt, I can say that getting started with Arduino is almost as easy as the directions! I have an Arduino Nano v3.0 with ENC28J60 ethernet shield and HTU21D temperature and humidity sensor module. But for reference, I did need to download drivers at Step 3, just not the FTDI driver mentioned. I needed to install a PL2303 driver for OS X 10.7 "Lion". There are many other PL2303 driver choices, too: from Prolific itself, on a plugable list, and from mac-usb-serial.

My first swing at it didn't work (no blinking light, but instead an upload error). That problem turned out to be that I had plugged everything into my oldest (and smallest) breadboard. The blink program successfully uploaded and worked with just Nano, and with Nano+Ethernet, so I only had to remove that breadboard to get it working. The first troubleshooting tip I tried was "Try uploading with nothing connected to the board (apart from the USB cable, of course)." Yay, that was it!

I consider my toes dipped in the water!