Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

XRAD'S Pip Boy 2000 Mk VI Working Geiger Counter
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

XRAD'S Pip Boy 2000 Mk VI Working Geiger Counter

by XRAD on Sun Oct 18, 2020 7:08 pm

Ok so it's not a reeeeeeal geiger PM tube or amp...too big and not sensitive enough to fit into this tiny little pip boy box ......
So I decided on using WiFi signal strength. Started out with feather Huzzah/M0 express combo, but also too big to fit into this wee box. Soooo...went with a D1 mini WiFi ESP8266 board w/4mb and a teensy 3.2. Tiny guy, and using the arduino library containing all the esp8266 boards including the Huzzah, it was fairly easy to get going. went with a powered piezo for a touch more volume and sharper notes. But the best part is the Adafruit OLED. The 1.3" monochrome fit nearly perfectly w/minor trimming and has aexcellent brightness and image rendering.

So the key parts of getting this to work is first getting the wifi signal strength in -dB's from all available wifi sources (my neighbors!!), converting it to abs(), and then averaging it so that it was not sending crazy HI-LOW wire.write data to the slave code. By the way, the ESP8266 has to be the master of communications!! Ok, so sending smoothed data from 0-100 (0 is strongest signal) and then mapping this to the needle sketch was pretty straightforward. Hardest part was actually 'drawing' the gauge face on MS paint and then converting the code to a bitmap (using this: https://lvgl.io/tools/imageconverter) which worked GREAT! If you zoom in enough on paint, you can 'paint' each pixel for 128x64. I could have made it fit the gauge face with a better arc, but ...too lazy..

ESP 8266 D1 to SCL and D2 to SDA for communications. One issue is that wire transmit/receive cause minor interrupts in my loop, but I could write that data to a buffer, and then read the buffer when certain criteria are met, However, since the interrupts are minimal, and the piezo sound is random, and needle movement intermittent, it does not really matter to me. I did try smoothing the needle movement a bit by drawing the positions between tip changes, but didn't quite work out..... You will also see FastLED library included. It provides a timer EVERY_N_MILLISECONDS which I use in various places .

Some of the needle drawing code from here(a good read):
https://forum.arduino.cc/index.php?topic=403234.0
some of the wifi code from here:
https://robojax.com/learn/arduino/?vid= ... _wifi_scan
some of the wire esp8266 code from here:
https://github.com/wemos/D1_mini_Exampl ... ecial/Wire
and of course Adafruit for the OLED code in the arduino examples!

Anyway, my code compilation is provided below. Wiring is super easy just using the pins described in the code. enjoy! Video at:
https://www.youtube.com/watch?v=Dn7wfkw7qyE


IMG_0444.JPG
IMG_0444.JPG (177.45 KiB) Viewed 126 times

IMG_0442.JPG
IMG_0442.JPG (158.89 KiB) Viewed 126 times


WiFi master code. load this to your ESP8266 board
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "ESP8266WiFi.h"

//average variables
const int numReadings = 3;//just average 3 readings
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

//WiFi data variables
int long sample ; //strength 'sample' of each node
int n = 1;// # of wifi nodes to begin at 1


void setup()
{
  //Wire.begin(D2, D1);    //D2 =SDA, D1 = SCL of I2C Bus
    Wire.begin();    //D2 =SDA, D1 = SCL of I2C Bus

  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  delay(2000);
  Serial.println("Start");
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
}


void loop() {
  for ( int i = 0; i < n; ++i) {
    n = WiFi.scanNetworks();
    sample = abs(WiFi.RSSI(i));
    total = total - readings[readIndex];
    readings[readIndex] = sample;
    total = total + readings[readIndex];
    readIndex = readIndex + 1;
    if (readIndex >= numReadings) {
      readIndex = 0;
    }
    average = total / numReadings;
    Wire.beginTransmission(5);
    Wire.write (average);
    Serial.println (average);
    Wire.endTransmission();
  }
}


Processor code (arduino/feather M0/teensy 3.2...etc..)

Code: Select all | TOGGLE FULL SIZE

#include <FastLED.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64// OLED display height, in pixels

int speakerPin = 5;//out to piezo buzzer

// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET -1//not used
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
                         OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

int ESPDATA;                          //ESP8266 I2C input for meter reading
int sample;
int hMeter = 65;                      // horizontal center for needle animation
int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
int rMeter = 80;                      // length of needle animation or arch of needle travel
float MeterValue ;

const int sampleWindow = 300;          // collect data every 'x' millis 
 
int long randomTickTime ;


//the Geiger O'Meter, draw a vertical meter
static const unsigned char PROGMEM geigerMeter[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xc0, 0x10, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x20, 0x00, 0xf8, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x40, 0x10, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0x00, 0x04, 0x00, 0x40, 0x10, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0x80, 0x04, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0xc0, 0x03, 0xff, 0x80, 0x00, 0x00, 0xff, 0x00, 0x80, 0x00, 0x40, 0x20, 0x00,
  0x00, 0xfe, 0x00, 0x60, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x80, 0x00, 0x80, 0x20, 0x00,
  0x00, 0x10, 0x00, 0x21, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x80, 0x20, 0x00,
  0x00, 0x10, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x01, 0x00, 0x20, 0x00,
  0x00, 0x10, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x02, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x20, 0x00,
  0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00,
  0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x06, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x87, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x9f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x01, 0x07, 0x9f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x07, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x01, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x06, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

int toneDelay;


void setup() {
  Wire.begin(5);
  Serial.begin(115200);

  randomSeed(analogRead(A0));

  if (!display.begin(SSD1306_SWITCHCAPVCC)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever, rut row :P
  }
  display.display();
  display.clearDisplay();
  testscrolltext();//"GEIGER INITIALIZE"
}

void loop() {

  unsigned long startMillis = millis();                    // start of sample window


  while ( millis() - startMillis < sampleWindow ) {

    Wire.onReceive(receiveEvent);
    //need to map incomming esp8266 data to get needle position off 'display midline "0"'
    sample = map(ESPDATA, 0, 100, -35 , 35 );
    //Serial.print("sample  ");
    //Serial.println(sample); 
    MeterValue = sample;
    drawNeedle();
    toneDelay = map(ESPDATA,  30, 70, 50 , 1000 );//value to ms delay
    tickTones();
  }
}


void receiveEvent(int howMany)
{
  ESPDATA = Wire.read();
  if (ESPDATA > 100) {
    ESPDATA = 100;
  }
  if (ESPDATA < 0) {
    ESPDATA = 0;
  }
  // Serial.print("ESPDATA  ");
  //Serial.println(ESPDATA);
}


void drawNeedle() {
  display.clearDisplay();
  display.drawBitmap(0, 0, geigerMeter, 128, 64, SSD1306_WHITE);   // draws background
  int a1 = (hMeter + (sin(MeterValue / 57.296) * rMeter)); // meter needle horizontal coordinate
  int a2 = (vMeter - (cos(MeterValue / 57.296) * rMeter)); // meter needle vertical coordinate
  display.drawLine(a1 - 1, a2, hMeter - 1, vMeter, SSD1306_WHITE); // draws needle
  display.drawLine(a1, a2, hMeter, vMeter, SSD1306_WHITE);         // draws needle middle line
  display.drawLine(a1 + 1, a2, hMeter + 1, vMeter, SSD1306_WHITE); // draws needle
  display.display();
  //Serial.println (MeterValue);
}


void tickTones() {

  if ( ESPDATA > 10  ) {
    EVERY_N_MILLIS_I(timerA, 100) {
      timerA.setPeriod(random(100, 3500) );
      tone(speakerPin, 1000, 5);
    }
  }

  if ( ESPDATA >= 30 && ESPDATA < 70) {
    EVERY_N_MILLISECONDS(toneDelay) {
      tone(speakerPin, 1000, 5);
      //Serial.print("tone delay:   ");
      //Serial.println (toneDelay);
    }
    EVERY_N_MILLIS_I(timerA, 100) {
      timerA.setPeriod(random(100, 800) );
      tone(speakerPin, 1000, 5);
    }
  }

  if ( ESPDATA < 30  ) {
    for (int i = 0; i < 10; i++) {
      tone(speakerPin, 1000, 5);
    }
  }
}

void testscrolltext(void) {
  display.clearDisplay();
  display.setRotation(3);
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(15, 40);
  display.print (F("GEIGER   "));
  display.println (F("INITILIZE"));
  display.display();
  delay(250);
  // Scroll in various directions, pausing in-between:
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.setRotation(0);//'reset' for rad meter orientation
}

XRAD
 
Posts: 660
Joined: Sat Nov 19, 2016 3:28 pm

Re: XRAD'S Pip Boy 2000 Mk VI Working Geiger Counter

by XRAD on Sat Oct 24, 2020 12:48 pm

So finished the code, added some lighted microbuttons, which lined up nicely with standard 0.1" bread board. Added buttons control to code and modified EVERY_N_MILLIS to stop log-jam. see the vid:
https://www.youtube.com/watch?v=ZfsTnBVWgdI

IMG_0447.JPG
IMG_0447.JPG (268.32 KiB) Viewed 96 times


final processor code (WiFi code remains as above):
Code: Select all | TOGGLE FULL SIZE

#include <FastLED.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64// OLED display height, in pixels

int speakerPin = 5;//out to piezo buzzer

// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET -1//not used
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
                         OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

int ESPDATA;                          //ESP8266 I2C input for meter reading
int sample;
int hMeter = 65;                      // horizontal center for needle animation
int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
int rMeter = 80;                      // length of needle animation or arch of needle travel
float MeterValue ;

#define sampleWindow  300          // timer in mS

unsigned long randomTickTime ;  // or int long

int toneDelay;


#define statPin  21   // the number of the pushbutton pin
#define itemPin  22
#define dataPin  23

#define statLEDPin  1  // the number of the LED pin
#define itemLEDPin  2
#define dataLEDPin  3


int statState = 0;         // variable for reading the pushbutton status
int itemState = 0;
int dataState = 0;



//the Geiger O'Meter, draw a vertical meter
static const unsigned char PROGMEM geigerMeter[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0xc0, 0x10, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x80, 0x10, 0x00, 0x80, 0x00, 0x20, 0x00, 0xf8, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x40, 0x10, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0x00, 0x04, 0x00, 0x40, 0x10, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0x80, 0x04, 0x07, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x10, 0x00, 0xc0, 0x03, 0xff, 0x80, 0x00, 0x00, 0xff, 0x00, 0x80, 0x00, 0x40, 0x20, 0x00,
  0x00, 0xfe, 0x00, 0x60, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x80, 0x00, 0x80, 0x20, 0x00,
  0x00, 0x10, 0x00, 0x21, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x80, 0x20, 0x00,
  0x00, 0x10, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x01, 0x00, 0x20, 0x00,
  0x00, 0x10, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x02, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc4, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x20, 0x00,
  0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x20, 0x00,
  0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00,
  0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00,
  0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x06, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x87, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x9f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x01, 0x07, 0x9f, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x07, 0xc0, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3f, 0x01, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x06, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};




void setup() {
  Wire.begin(5);
  Serial.begin(115200);

  randomSeed(analogRead(A0));

  if (!display.begin(SSD1306_SWITCHCAPVCC)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever, rut row :P
  }
  display.display();
  display.clearDisplay();

  pinMode(statLEDPin, OUTPUT);
  pinMode(itemLEDPin, OUTPUT);
  pinMode(dataLEDPin, OUTPUT);

  pinMode(statPin, INPUT_PULLDOWN);
  pinMode(itemPin, INPUT_PULLDOWN);
  pinMode(dataPin, INPUT_PULLDOWN);
  digitalWrite(statLEDPin, HIGH);
  digitalWrite(itemLEDPin, HIGH);
  digitalWrite(dataLEDPin, HIGH);
  testscrolltext();//"GEIGER INITIALIZE"
  digitalWrite(statLEDPin, LOW);
  digitalWrite(itemLEDPin, LOW);
  digitalWrite(dataLEDPin, LOW);
}

void loop() {
  unsigned long startMillis = millis();                    // start of sample window

  statState = digitalRead(statPin);
  itemState = digitalRead(itemPin);
  dataState = digitalRead(dataPin);


  if (statState == HIGH) {
    // turn LEDs on/off:
    digitalWrite(statLEDPin, HIGH);
    digitalWrite(itemLEDPin, LOW);
    digitalWrite(dataLEDPin, LOW);
  }
  if (itemState == HIGH) {
    // turn LEDs on/off:
    digitalWrite(statLEDPin, LOW);
    digitalWrite(itemLEDPin, HIGH);
    digitalWrite(dataLEDPin, LOW);
  }
  if (dataState == HIGH) {
    // turn LEDs on/off:
    digitalWrite(statLEDPin, LOW);
    digitalWrite(itemLEDPin, LOW);
    digitalWrite(dataLEDPin, HIGH);
  }


  toneDelay = map(ESPDATA,  20, 70, 50 , 600 );//value to ms delay 70/600
  //Serial.print("tone delay:   ");
  //Serial.println (toneDelay);

  while ( millis() - startMillis < sampleWindow ) {

    Wire.onReceive(receiveEvent);
    //need to map incomming esp8266 data to get needle position off 'display midline "0"'
    sample = map(ESPDATA, 0, 100, -40 , 40 );
    //Serial.print("sample  ");
    //Serial.println(sample);
    MeterValue = sample;
    drawNeedle();
    //toneDelay = map(ESPDATA,  30, 70, 50 , 1000 );//value to ms delay
    tickTones();
  }
}

void receiveEvent(int howMany)
{
  ESPDATA = Wire.read();
  if (ESPDATA > 100) {
    ESPDATA = 100;
  }
  if (ESPDATA < 0) {
    ESPDATA = 0;
  }
  //Serial.print("ESPDATA  ");
  // Serial.println(ESPDATA);
}


void drawNeedle() {
  display.clearDisplay();
  display.drawBitmap(0, 0, geigerMeter, 128, 64, SSD1306_WHITE);   // draws background
  int a1 = (hMeter + (sin(MeterValue / 57.296) * rMeter)); // meter needle horizontal coordinate
  int a2 = (vMeter - (cos(MeterValue / 57.296) * rMeter)); // meter needle vertical coordinate
  display.drawLine(a1 - 1, a2, hMeter - 1, vMeter, SSD1306_WHITE); // draws needle
  display.drawLine(a1, a2, hMeter, vMeter, SSD1306_WHITE);         // draws needle middle line
  display.drawLine(a1 + 1, a2, hMeter + 1, vMeter, SSD1306_WHITE); // draws needle
  display.display();
  //Serial.println (MeterValue);
}


void tickTones() {

  if ( ESPDATA < 20  ) {
    for (int i = 0; i < 10; i++) {
      tone(speakerPin, 1000, 5);
    }
  }

  else if ( ESPDATA >= 20 && ESPDATA < 50) {
    EVERY_N_MILLIS_I(timerB, toneDelay) {
      timerB.setPeriod(random(50, 300) );
      tone(speakerPin, 1000, 5);

    }
    EVERY_N_MILLIS_I(timerA, 100) {
      timerA.setPeriod(random(100, 800) );
      tone(speakerPin, 1000, 5);
    }
  }

  else if ( ESPDATA >= 50 && ESPDATA < 70) {
    EVERY_N_MILLIS_I(timerD, toneDelay) {
      timerD.setPeriod(random(100, 1000) );
      tone(speakerPin, 1000, 5);

    }
    EVERY_N_MILLIS_I(timerE, 100) {
      timerE.setPeriod(random(50, 1000) );
      tone(speakerPin, 1000, 5);
    }
  }

  else if ( ESPDATA >= 70 && ESPDATA < 95) {
    EVERY_N_MILLIS_I(timerC, 500) {
      timerC.setPeriod(random(100, 3500) );
      tone(speakerPin, 1000, 5);
    }
  }
}


void testscrolltext(void) {
  display.clearDisplay();
  display.setRotation(3);
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(15, 40);
  display.print (F("GEIGER   "));
  display.println (F("INITILIZE"));
  display.display();
  delay(250);
  // Scroll in various directions, pausing in-between:
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.setRotation(0);//'reset' for rad meter orientation
}

XRAD
 
Posts: 660
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.