<commit_before>* Introduction
This is the source code for a weather station where multiple stations
send wirelessly their data to a dedicated base. The hardware design is
based around the Atmel ATmega88PA, Bosch BMP085, Sensirion SHT75x and
a Davis rain measurement unit. Data transmission is done with the
nRF24L01+.

Currently missing is the hardware schematic and PCB design which will
be added later. It exists at the moment only on bread boards.



* Open points/Todos
** TODO ATmega88PA supports pin toggle natively
#+BEGIN_SRC c
  PINB |= (1 << PINB1); // toggle the I/O port output pin
#+END_SRC

** TODO Clean up wireless high level code 
** TODO Integrate IIR filter?
   Use a warm up loop after reset to warm up the filter value.
   #+BEGIN_SRC c
     #include <stdint.h>
     #include <stdio.h>

     /**
      ,* @brief Approximation for IIR filter of \f$log2(1/\alpha)\f$.
      ,* @details This is roughly \f$ log2(1 / \alpha) \f$.
      ,*/
     #define IIR_FILTER_BITS 2

     /**
      ,* @brief   IIR filter for long values.
      ,* @details Implement a first order IIR (infinite impulse response) filter
      ,*          to approximate a K sample moving average.
      ,*
      ,*          This function implements the equation:
      ,*          \f$ y_n = \alpha * x_n + (1-\alpha) * y_{n-1 } \f$.
      ,*
      ,* @see     http://is.gd/gx3kVm.
      ,*
      ,* @param filter - a signed fixed-point value like 15.42. Choose
      ,* initial value with a reasonable start value according to the dataset.
      ,* @param   sample - the 16-bit value of the current sample.
      ,*/
     uint16_t lowpass_filter(uint32_t *filter, uint16_t sample)
     {
         uint32_t local_sample = sample << 16;

         ,*filter += (local_sample - *filter) >> IIR_FILTER_BITS;

         return (uint16_t) ((*filter+0x8000) >> 16); // Round by adding .5 and truncating.
     }

     int main(int argc, char *argv[])
     {
         uint32_t filter;
         uint16_t data[] = {
             1013, 1012, 1003, 1005, 999, 1014, 1002, 1005, 1019, 1012, 999, 1012, 1003,
             1011, 1020, 1001, 1009, 1008, 1003, 1007, 1014, 1019, 1011, 1015, 1008, 1008,
             1001, 1023, 1007, 1005, 1016, 1014, 1001, 1021, 1016, 1023, 1023, 1010, 1014,
             1006, 999, 1020, 1010, 1005, 1011, 1001, 1018, 1001, 1002, 1004, 1012, 1008
         };

         filter = 66000000;
         unsigned int n;
         for (n = 0; n < sizeof(data)/sizeof(*data); n++) {
             short sample = data[n];
             long filter_save = filter;
             short res = lowpass_filter(&filter, sample);
             printf("%ld\t%2hd\t%2hd\n", filter_save, sample, res);
         }

         return 0;
     }

#+END_SRC

** TODO Main timer higher prescaler
** TODO SHT7x Socket Connector
** TODO Use 32.768 kHz oscillator as main clock?
   Compare current consumption of internal vs. external clock in data sheet.
** TODO Rainsensor use CTC?
** TODO Rainsensor use 0.2mm in base.c for output
** TODO Use error handling with SHT11, BMP085 in main


* Electrical characteristics

|               | U min | U Max | I min/µA | I max/mA |
|---------------+-------+-------+----------+----------|
| ATmega88PA 1) |   1.8 |   5.5 |      0.9 |      2.5 |
| BMP085        |   1.8 |   3.6 |      3.0 |    0.005 |
| SHT7x   2)    |   2.4 |   5.5 |      1.5 |     0.91 |
| nRF24L01+ 3)  |   1.9 |   3.3 |      0.9 |     11.3 |
| MS5611        |   1.8 |   3.6 |     0.14 |   0.0125 |
| NCR18650B     |   2.5 |   4.2 |          |          |

1) With external 32.768 kHz oscillator, which is not actually used
   to drive the system clock, but it is active during power save to
   drive the asynchronous timer to wake the MCU.
2) Needs voltage compensation, i.e. fixed power supply required
3) Needs 3.3V at max, also for input signals (i.e. MCU signals)
<commit_msg>Update readme.<commit_after>* Introduction
This is the source code for a weather station where multiple stations
send wirelessly their data to a dedicated base. The hardware design is
based around the Atmel ATmega88PA, Bosch BMP085, Sensirion SHT75x and
a Davis rain measurement unit. Data transmission is done with the
nRF24L01+.

Currently missing is the hardware schematic and PCB design which will
be added later. It exists at the moment only on bread boards.

The base received all measurements from the stations and gathers them.
These data will be written as JSON to the UART. Currently a
Raspberry PI is connected to the base UART, where a seperate program
parses the JSON data and stores it into a time series database.

* Open points/Todos
** TODO ATmega88PA supports pin toggle natively
#+BEGIN_SRC c
  PINB |= (1 << PINB1); // toggle the I/O port output pin
#+END_SRC

** TODO Clean up wireless high level code 
** TODO Main timer needs higher prescaler
** TODO Order SHT7x Socket Connector
** TODO Use CTC mode for rainsensor coding
** TODO Use 0.2mm in basec. for rainsensor output
** TODO Use error handling with SHT11, BMP085 in main

* Electrical characteristics
|               | U min | U Max | I min/µA | I max/mA |
|---------------+-------+-------+----------+----------|
| ATmega88PA 1) |   1.8 |   5.5 |      0.9 |      2.5 |
| BMP085        |   1.8 |   3.6 |      3.0 |    0.005 |
| SHT7x   2)    |   2.4 |   5.5 |      1.5 |     0.91 |
| nRF24L01+ 3)  |   1.9 |   3.3 |      0.9 |     11.3 |
| MS5611        |   1.8 |   3.6 |     0.14 |   0.0125 |
| NCR18650B     |   2.5 |   4.2 |          |          |

1) With external 32.768 kHz oscillator, which is not actually used
   to drive the system clock, but it is active during power save to
   drive the asynchronous timer to wake the MCU.
2) Needs voltage compensation, i.e. fixed power supply required
3) Needs 3.3V at max, also for input signals (i.e. MCU signals)

{'fraction_non_alphanumeric': 0.11241379310344828, 'fraction_numerical': 0.08172413793103449, 'mean_word_length': 2.19262520638415, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2908553', 'n_tokens_mistral': 2178, 'n_tokens_neox': 1842, 'n_words': 735}