SolarRC: Difference between revisions

From SGMK-SSAM-WIKI
Jump to navigation Jump to search
Line 52: Line 52:


* Make your Arduino IDE ready to build and program the ATtiny. ManchesterRF relies on that Arduino environment. - http://highlowtech.org/?p=1695
* Make your Arduino IDE ready to build and program the ATtiny. ManchesterRF relies on that Arduino environment. - http://highlowtech.org/?p=1695
* Make tiny modification in the ManchasterRF lib itself. Somehow it still works, and will not compile otherwise...
* Make tiny modification in the ManchasterRF lib itself; it will not compile otherwise. Somehow it still works without that interrupt handler... Replace the junk at the end of the ManchesterRF.cpp file with this:
 
At the end of the ManchesterRF.cpp file:
 
<pre>
<pre>



Revision as of 20:43, 6 May 2015

Description

A quite inexpensive and simple solar powered AVR ATtiny circuit to collect data from the environment.


Overview

We've tested the following hardware:


In combination with:

  • 2x Arduinos (on the same computer, good for debugging via serial monitor - just start the arduino IDE twice)
  • 2x ATtiny85 (great for final devices, placed somwhere outside)


Software: Those two Arduino libraries were tested successfully:


Tests showed that it is possible to transmit data reliably indoor up to a distance of about 20 meters. The signal gets weaker, depending on the obstacles between sender/receiver of course. To improve the signal quality it was helpful to use a simple wire on stick of 17.3cm in length (quarter wavelength) as an antenna on both, sender/receiver modules.

TODO

  • Measure power consumption and average solar charging rate... is it possible to run the device non-stop, also during the night, collecting data?
  • Investigate more about low power usage/sleep mode... and energy harvesting in general.
  • What's the minimal number of parts/price needed to shrinkify the the whole setup to a single board? (3.3 V?)
  • Mesh network with receiver/transmitter pair (transceiver) on every node? Can the nodes be used as "relays" to increase transmission range? What kind of protcol is ideal for this? How to minimize collisions/corrupted data (send checksum)? Does it make sense ($$$) compared to XBee, BLE, WiFi etc.?
  • It is possible make a very simple radio transmitter, by using just the internal oscillator of the microcontroller! Have a look at this great hack by Scott W Harden. To receive the data, a diode detector could be used to demodulate the AM signal and read it in again on an analog pin... but this is just fantasy, no clue if/how/how good this will work, we'll see...

Setup

Transmitter setup:


Sender and receiver module:

Code

Here are the examples from the ManchesterRF lib.

There are two things to think about, when you try this to run on the ATtiny85:

  • Make your Arduino IDE ready to build and program the ATtiny. ManchesterRF relies on that Arduino environment. - http://highlowtech.org/?p=1695
  • Make tiny modification in the ManchasterRF lib itself; it will not compile otherwise. Somehow it still works without that interrupt handler... Replace the junk at the end of the ManchesterRF.cpp file with this:

// MOD MOD MOD
#if defined( __AVR_ATtinyX5__ )
#else
//#if defined( __AVR_ATtinyX5__ )
//	ISR(TIMER1_OVF_vect)
//#elif ...

#if defined( __AVR_ATtinyX4__ )
	ISR(TIM1_OVF_vect)
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1284P__)
	ISR(TIMER3_OVF_vect)
#elif defined(__AVR_ATmega328P__)
	ISR(TIMER2_OVF_vect)
#else
	#error "Manchester library doesnt support your microcontroller"
#endif
{
  DEBUG_TOGGLE();
	MAN_RX_INTERRUPT_HANDLER();
}

#endif // MOD


Then it should build and run just fine. Play around with different link speeds and transmission distances...

Any hints and ideas about this are always welcome! This is a little work in progress experiment...


Transmitter

/*

  Manchester Receiver example
  
  In this example transmitter will transmit two 8 bit numbers per transmittion
    
*/


#include "ManchesterRF.h" //https://github.com/cano64/ManchesterRF


#define TX_PIN 3 //any pin can transmit
#define LED_PIN 13

ManchesterRF rf(MAN_300); //link speed, try also MAN_300, MAN_600, MAN_1200, MAN_2400, MAN_4800, MAN_9600, MAN_19200, MAN_38400

uint8_t data = 0;

boolean state = false;

void setup() {
  pinMode(LED_PIN, OUTPUT);  
  digitalWrite(LED_PIN, HIGH);
  rf.TXInit(TX_PIN);
  
  Serial.begin( 9600 );
}

void loop() {

  int a, b;
  rf.transmitByte(a = ++data, b = data*data);
  digitalWrite(LED_PIN, state); //blink the LED on receive
  state = !state;
  
  Serial.print( a );
  Serial.print( ", " );
  Serial.print( b );
  Serial.println();
  delay(500);
}


Receiver

/*

  Manchester Receiver example
  
  In this example receiver will receive two 8 bit numbers per transmittion

*/


#include "ManchesterRF.h" //https://github.com/cano64/ManchesterRF

#define RX_PIN 4 //any pin can receive
#define LED_PIN 13

ManchesterRF rf(MAN_300); //link speed, try also MAN_300, MAN_600, MAN_1200, MAN_2400, MAN_4800, MAN_9600, MAN_19200, MAN_38400

uint8_t a, b;

boolean state = false;

void setup() {
  pinMode(LED_PIN, OUTPUT);  
  digitalWrite(LED_PIN, HIGH);
  rf.RXInit(RX_PIN);
  
  Serial.begin( 9600 );
}

void loop() {

  if (rf.available()) { //something is in RX buffer
    if (rf.receiveByte(a, b)) {
      //process the data
      //...
      digitalWrite(LED_PIN, state); //blink the LED on receive
      state = !state;
      
      Serial.print( a );
      Serial.print( ", " );
      Serial.print( b );
      Serial.println();
    }
  }
}