Spirit level help

Hi
I was looking at doing the Digital spirit level from the blog here:

The only problem is, that in the past 2 days, the link no longer works? I don't know much about the internet, so I don't know why!

My questions are..

  1. Is the site likely to come back up?
  2. Does anyone else have access to a copy of this guide, Maybe you have followed it before and saved a copy?

I know it's a long shot, and knowing me very possibly in the wrong forum but thanks in advance.

I couldn't find a google-cache page (must say I'm no expert in searching cached pages as well) and it probably looks different as supposed to, but here's some info you may be looking for.

  1. Is the site likely to come back up?

It looks like the "rental" on that URL or on the server that it points to as run out.

do a google search for :-
digital-spirit-level-adxl345-tft-display-hy-1-8-spi-and-an-arduino
and use the arrow underneath the match to select the cached version. When I tried this there was not much success.

However the third link was to a printerst web site that showed me some photos before it asked me to log in or create an account, which I declined to do.

That looks right, I'm on my phone so I will have to try at home.

Thanks guys :slight_smile:

I put the link into the wayback machine.

got this

shame the poster did not keep current.
looks like he is talented.

Yeah, the guy seems really good, It's a real shame. I tried to contact him through YouTube and chrome links, so hopefully he might bring it back.
I didn't notice there was a donate page :frowning: I Feel bad I didn't support it.

Thanks Again Folks.

I used a Sparkfun ring LED and an ADXL345 to make a bubble level a long time ago. This was a step towards developing a simple library which only exposed the one function I needed from the ADXL345. As a result, it does depend on one of my other programs to store some calibration data in the EEPROM. You could just hand-code the values into that function for testing.

Code attached. Let me know if there's any questions.

RingCoderBubble.ino (10 KB)

Well, I have managed to build the project, but...... when I connect the ADXL345
It stops working (Screen goes White).
The other problem is I can't seem to power the Nano off the board as well as the screen?
Using a 9v battery??

Screen? What screen? LCD screens use a lot of of power due to the necessary backlight.

Post your code. With code tags.

Hi
Well I have it working :slight_smile: It seems the ebay seller lied about the ADXL being either 3.3v OR 5v! I had to change my wiring aswell for some reason, 1 being my breadboard was not powering correctly and I had to put the Ground of my ADXL345 to the Grnd on the NANO??? as opposed to supply Ground.

I would like to bring up a message first (Kind of a user guide/Disclaimer) Before the spirit level comes on, but since I got the code elsewhere I Don't know how to code That in!

I would also Like to find out how accurate this is set to measure Eg. is it set to 1Deg, a few degrees? It should be able to work out in the code I think?

Cheers

#include <Wire.h>
#include <ADXL345.h>

#define cs   10 // Arduino-Pin an Display CS   
#define dc   9  // Arduino-Pin an Display A0
#define rst  8  // Arduino Reset-Pin

#include "Adafruit_GFX.h"    // Adafruit Grafik-Bibliothek
#include "Adafruit_ST7735.h" // Adafruit ST7735-Bibliothek
#include <SPI.h>

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);  // Display-Bibliothek Setup


ADXL345 accel;

#define button_correction 3

void setup(void){

  Serial.begin(9600);

  pinMode(button_correction, INPUT);

  // Sensor
  accel.begin();        // Sensor initialisieren
  accel.setRange(accel.RANGE_16G);  // Empfindlichkeit einstellen
  
  // Display
  tft.initR(INITR_BLACKTAB);    // ST7735-Chip initialisieren
  tft.setTextWrap(true); 
  
  display_show();
}

const float alpha = 0.5;
double fXg = 0;
double fYg = 0;
double fZg = 0;

double x_correction=0;
double y_correction=0;

int x_value=0;
int y_value=0;
int old_x_value=1;
int old_y_value=1;

#define filter_count_max 40
byte filter_count=0;

#define correction_precision 300  // Sollte Anzeige im Liegen wackeln Wert vermindern

void loop(void){
 
  double pitch, roll, Xg, Yg, Zg;
  accel.read(&Xg, &Yg, &Zg);
  
  fXg+=Xg;
  fYg+=Yg;
  filter_count++;
  
  if(filter_count==filter_count_max-1){
  
    fXg/=filter_count_max;
    fYg/=filter_count_max;

    if(digitalRead(button_correction)==HIGH){
      x_correction=fXg; 
      y_correction=fYg;
    }
    
    x_value=(fXg-x_correction)*correction_precision;
    y_value=(fYg-y_correction)*correction_precision;

    //display_info();
    display_graphic();
    
    old_x_value=x_value;
    old_y_value=y_value;
    
    fXg=0;
    fYg=0;
    filter_count=0;
  }
  
  delay(5);

}

#define hx 27
#define hy 16
#define hw 95
#define hh 18
#define hb 7

#define vx 5
#define vy 38
#define vw 18
#define vh 95
#define vb 7

#define cx 75
#define cy 86
#define cr 45
#define cb 5

void display_show(){

  tft.fillScreen(ST7735_BLACK); 
  
  set_text(32,3,"Wasserwaage",ST7735_BLUE,1);  
  set_text(14,149,"blog.simtronyx.de",ST7735_GREEN,1);
  
  tft.drawRect(hx-1,hy-1,hw+2,hh+2,rgb565(128,128,128));
  tft.drawRect(hx+1,hy+1,hw-2,hh-2,rgb565(128,128,128));
  tft.drawRect(hx,hy,hw,hh,ST7735_WHITE);
  
  tft.drawRect(vx-1,vy-1,vw+2,vh+2,rgb565(128,128,128));
  tft.drawRect(vx+1,vy+1,vw-2,vh-2,rgb565(128,128,128));
  tft.drawRect(vx,vy,vw,vh,ST7735_WHITE);
  
  tft.drawCircle(cx,cy,cr+1,rgb565(128,128,128));
  tft.drawCircle(cx,cy,cr-1,rgb565(128,128,128));
  tft.drawCircle(cx,cy,cr,ST7735_WHITE);
}

void display_graphic(){
  
  if(x_value!=old_x_value){
    
    tft.drawRect(hx+hw/2+constrain(old_x_value,-hw/2+(hb+1)/2,hw/2-(hb+1)/2)-(hb-1)/2,hy+2,hb,hh-4,rgb565(0,0,0));
    tft.drawRect(hx+hw/2,hy+2,1,hh-4,rgb565(255,255,255));
    tft.drawRect(hx+hw/2+constrain(x_value,-hw/2+(hb+1)/2,hw/2-(hb+1)/2)-(hb-1)/2,hy+2,hb,hh-4,rgb565(0+constrain(abs(x_value)*10,0,255),255-constrain(abs(x_value)*10,0,255),0));
  }
    if(y_value!=old_y_value){
    
    tft.drawRect(vx+2,vy+vh/2-(constrain(old_y_value,-vh/2+(vb+1)/2,vh/2-(vb+1)/2)+(vb-1)/2),vw-4,vb,rgb565(0,0,0));
    tft.drawRect(vx+2,vy+vh/2,vw-4,1,rgb565(255,255,255));
    tft.drawRect(vx+2,vy+vh/2-(constrain(y_value,-vh/2+(vb+1)/2,vh/2-(vb+1)/2)+(vb-1)/2),vw-4,vb,rgb565(0+constrain(abs(y_value)*10,0,255),255-constrain(abs(y_value)*10,0,255),0));
  }
  if((x_value!=old_x_value)||(y_value!=old_y_value)){

    float hxv=old_x_value;
    float hyv=old_y_value;
    float l=sqrt(hxv*hxv+hyv*hyv);
    if(l>cr-cb-2){
      hxv=hxv/l*(cr-cb-2);
      hyv=hyv/l*(cr-cb-2);
    }
    
    tft.fillCircle(cx+hxv,cy-hyv,cb,rgb565(0,0,0));
    tft.drawCircle(cx,cy,cb+2,rgb565(255,255,255));
    
    hxv=x_value;
    hyv=y_value;
    l=sqrt(hxv*hxv+hyv*hyv);
    if(l>cr-cb-2){
      hxv=hxv/l*(cr-cb-2);
      hyv=hyv/l*(cr-cb-2);
    }
    tft.fillCircle(cx+hxv,cy-hyv,cb,rgb565(0+constrain((((abs(x_value)+abs(y_value))/2)*10),0,255),255-constrain((((abs(x_value)+abs(y_value))/2)*10),0,255),0));
  }
}

void display_info(){
     
  if(x_value!=old_x_value){
  
    set_text(4,16,value_to_string(old_x_value),ST7735_BLACK,1);
    set_text(4,16,value_to_string(x_value),ST7735_WHITE,1);
  }
  
    if(y_value!=old_y_value){
    
    set_text(4,26,value_to_string(old_y_value),ST7735_BLACK,1);
    set_text(4,26,value_to_string(y_value),ST7735_WHITE,1);
  }
}


void set_text(int x,int y,String text,int color,int size){
  
  tft.setTextSize(size);
  tft.setCursor(x,y);
  tft.setTextColor(color);
  tft.print(text);
}

// Hilfsfunktionen
uint16_t rgb565(uint8_t r, uint8_t g, uint8_t b){

  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

String value_to_string(int value){
  
  String value_string = String(value);
  return value_string;
}

Hi,
To check calibration you will have to use an external device to set your angles.
Plum-bob and protractor?

Tom... :slight_smile:

yeah unfortunately it seems that way. It does reset after power off to the same position, unfortunalty it's not the position I want!

Anyone got any idea about how to add some text before it starts?

Or how to reset the standard level point when I power off and on?