Wednesday, 15 January 2014

TinySensor (part 1)

TinySensor circuit diagram
Remote sensing using microcontrollers is nothing new --- it is practically a rite of passage. My spin on it, TinySensor, can be seen above. It's a wireless, battery-powered device which periodically transmits readings of light, temperature, humidity and its own battery voltage, to a base station comprising a Raspberry Pi and a MySQL database. Unusual features of this sensor are:
Resources:

14 comments:

  1. Nice blog :) Been following with great interest.

    Regarding the SPI emulation, do I put this in my libraries folder or elsewhere, and will it interfere with 328 based projects?

    ReplyDelete
    Replies
    1. You put it in your sketchbook/libraries folder. It's compatible with both ATMega and ATtiny.

      Delete
  2. Hi, this is great work, and thanks for sharing it!
    I'm trying to get RF24 working on ATTiny85, so I can have just a very simple temp and humidity node. I basically have it working with your modded libraries with the hellotx sketch, but it only works about 1 in 30 times - it says it failed, and the receiver doesn't get it either. In contrast, the same program and libraries work 100% on an Arduino Pro 3.3V. I've just got it running on a breadboard, I've tried injecting more 3.3V power, about the only thing I can think of is that it's using the 8MHz internal oscillator, but it seems you're doing the same.

    Any idea what the problem might be? Places to look?

    Thanks very much,
    Joel

    ReplyDelete
    Replies
    1. I had great difficulty getting started until I soldered a decoupling capacitor across the power pins of the radio. (It looks like this is missing in the circuit diagram above.)

      The first time round I used a 10u electrolytic capacitor; in the final circuit I used 100n.

      Hope this helps!

      Delete
    2. I put a 10uF across the power pins of the Tiny, which are the same power pins as the radio; does it need to be right on the radio module itself? Mind you the radios were very cheap, maybe because they skimped on parts...
      Thanks!

      Delete
    3. Wikipedia says this about placement: "A transient load decoupling capacitor should usually be placed as close as possible to the device requiring the decoupled signal."

      https://en.wikipedia.org/wiki/Decoupling_capacitor

      So yeah, if you can manage it, solder it onto the module itself.

      Delete
  3. OK, I soldered a 10uF 25V onto the pins of the module which is as close as I can get to the chip itself. Now it seems to be working almost exactly every 4 goes.
    Another thing I notice is that the Pro Mini version sends the time at exactly 1000ms, ie the ping received is 2000,4000, etc. But the tiny version, which I set at interval of 1500ms, loses a few ms each time. Maybe it's taking longer to do network.update(), or this function isn't operating correctly?

    ReplyDelete
    Replies
    1. Without knowing more about your setup, I can't really comment. You could try replacing the ATtiny with an ATmega on the breadboard and see if that made a difference to the timing or the reliability.

      You could add more smoothing capacitors to your 3v3 supply (where is that coming from?). I would imagine there is still a lot of noise around the breadboard (and jumpers which you must have used to connect the radio).

      I'm pretty sure network.update() is working fine. It may be that it has to do several retries to get the message through.

      You could change the data rate or the number of retries to see if it makes a difference. See the class docs here:
      https://maniacbug.github.io/RF24/classRF24.html

      You could also read the comments on Maniacbug's original blog post here:
      http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/

      Delete
    2. Yeah, thanks, I'll try doing it on a protoboard and see if that works better. Probably dodgy breadboard connections.

      I've got an ATmega running a radio in a very similar fashion, flawlessly. They also run off the same 3.3V power from USB via a regulator on the USBasp. Then I plugged in an additional 3.3v external source but that hasn't helped.

      So besides some dodgy wires, the main difference is in the chips themselves and the way they run - it might be the same sketch, but the ATtiny compiled code is much smaller, as well as being a different architecture and running at half the clock speed.

      Will let you know how it goes, thanks for your help!

      Delete
    3. Actually I think the architectures are very similar, the difference in size is due printf() being excluded on the tiny.

      You could also try powering it from a battery via a 3v3 LDO regulator. This might isolate it from one source of noise...

      Delete
    4. Hi, sorry to keep bothering you. I've moved away from the ATTiny85 for the moment and focused on getting everything else to work with an atmega. I've got all of your code running and recording data except the viewer with leiningen/clojure, which I'm not familar with. Is this working for you as a fresh git clone? First, the jar has no main class, so I added that to the project but there are problems building. I tried running it in the IDE on my mac but I get errors that appear to be due to differing compiler/runtime versions. What is the local jvm dir supposed to do? I had to create an empty dir for it to compile, but even if I symlink it to the current JAVA_HOME it doesn't fix my problems.
      Thanks
      Joel

      Delete
  4. Huh, interesting. Whichever way lein is invoking the Clojure compiler, you have to give it :requires as vectors not lists. (I'd been running this from IntelliJ with the Cursive plugin and it was all fine there.)

    Anyway, try it now, it now works for me from "lein run".

    ReplyDelete
    Replies
    1. I switched from my mac to Linux Mint VM as the mac was having weird errors (and is old). I don't know if I don't have the right versions but it won't compile or run. If you run it just appears to hang. On compilation, there are a few errors and then it just stops. No CPU, just won't return to prompt.

      joel@joel-mint-VirtualBox ~/src/TinySensors/sensing $ lein compile
      Compiling sensing.ui
      Reflection warning, seesaw/table.clj:83:9 - call to getColumnClass can't be resolved.
      Reflection warning, seesaw/table.clj:64:9 - call to insertRow can't be resolved.
      Reflection warning, seesaw/table.clj:59:9 - call to addRow can't be resolved.
      Reflection warning, seesaw/core.clj:937:5 - call to setLayout can't be resolved.
      Reflection warning, seesaw/core.clj:1489:68 - call to java.lang.Integer ctor can't be resolved.
      Reflection warning, seesaw/core.clj:1489:68 - call to java.lang.Integer ctor can't be resolved.
      Reflection warning, seesaw/core.clj:1489:68 - call to java.lang.Integer ctor can't be resolved.
      Reflection warning, seesaw/core.clj:1489:68 - call to java.lang.Integer ctor can't be resolved.
      Reflection warning, seesaw/core.clj:1731:53 - call to setWidth can't be resolved.
      Reflection warning, seesaw/core.clj:1731:69 - call to setPreferredWidth can't be resolved.
      Reflection warning, seesaw/core.clj:1733:51 - reference to field getWidth can't be resolved.
      Reflection warning, seesaw/core.clj:1907:17 - call to javax.swing.SpinnerNumberModel ctor can't be resolved.
      Reflection warning, seesaw/core.clj:2513:18 - call to paintComponent can't be resolved.
      Reflection warning, seesaw/core.clj:2617:9 - reference to field invalidate can't be resolved.
      Reflection warning, seesaw/core.clj:2617:9 - reference to field validate can't be resolved.
      Reflection warning, seesaw/core.clj:2617:9 - reference to field repaint can't be resolved.
      Reflection warning, seesaw/core.clj:2634:5 - call to setTransferHandler can't be resolved.
      Reflection warning, seesaw/core.clj:2634:5 - reference to field getTransferHandler can't be resolved.
      Reflection warning, clj_time/core.clj:577:10 - reference to field getDayOfMonth can't be resolved.
      Reflection warning, clojure/java/jdbc.clj:418:16 - reference to field executeBatch can't be resolved.
      Reflection warning, clojure/java/jdbc.clj:420:13 - reference to field getUpdateCount can't be resolved.
      Reflection warning, korma/db.clj:142:31 - call to endsWith can't be resolved.
      Reflection warning, korma/db.clj:204:5 - reference to field printStackTrace can't be resolved.
      Reflection warning, korma/db.clj:206:21 - reference to field getNextException can't be resolved.
      Reflection warning, korma/sql/engine.clj:84:42 - call to indexOf can't be resolved.
      Reflection warning, sensing/data.clj:19:13 - call to plus can't be resolved.
      Reflection warning, sensing/data.clj:59:57 - reference to field toLowerCase can't be resolved.

      lein version shows: Leiningen 1.7.1 on Java 1.7.0_60 Java HotSpot(TM) 64-Bit Server VM

      What versions are you running?

      Thanks
      Joel

      Delete
    2. (You could try upgrading lein. If it can't find the Java APIs, something is badly messed up...)

      steve@lenovo:~/src/Sensorhub/sensing$ lein -v
      Leiningen 2.0.0 on Java 1.7.0_55 Java HotSpot(TM) Client VM

      Delete