Thursday, May 18, 2023

0000 0000 1100 1010

The Dirty Dozen - Part Six: USB-C Nano, LIS3DH & Channel Update

The packet reveals an Arduino Nano? Hardly exciting, although I'd never had a Nano with a USBC interface before, but still it wasn't exactly a challenging unit!

So I dived backward to Dirty Dozen #5, dragged out the LIS3DH and interrogated it's temperature abilities. It's a little unusual in that the unit only reports the relative temperature based on when it was booted - strange!

I decided to use that with three LEDs to indicate relative temperature - here is the code:

/*
  Based on ADCUsage.ino

  Marshall Taylor @ SparkFun Electronics
  Nov 16, 2016
  https://github.com/sparkfun/LIS3DH_Breakout
  https://github.com/sparkfun/SparkFun_LIS3DH_Arduino_Library

  OneCircuit https://www.youtube.com/@onecircuit-as
  Mon 15 May 2023 11:02:06 AEST

*/

#include "SparkFunLIS3DH.h"
#include "Wire.h"

LIS3DH myIMU;
int myroomtemp = 0;
int currenttemp = 0;
int difftemp = 0;
#define blueled 4
#define greenled 3
#define yellowled 2

void setup() {

  Serial.begin(57600);
  delay(1000);
  pinMode(blueled, OUTPUT);
  pinMode(greenled, OUTPUT);
  pinMode(yellowled, OUTPUT);
  myIMU.settings.adcEnabled = 1;
  myIMU.settings.tempEnabled = 1; // from ADC3
  myIMU.begin();

  // take the temp
  for (byte stable = 0; stable < 5; stable++) {
  myroomtemp = myIMU.read10bitADC3(); // temp
  delay(100);    
  }
}

void loop()
{
  currenttemp = myIMU.read10bitADC3();
  difftemp = myroomtemp - currenttemp;

  Serial.println(difftemp);

  if (difftemp < 0) {
    digitalWrite(blueled, HIGH);
    digitalWrite(greenled, LOW);
    digitalWrite(yellowled, LOW);
  }
  if ((difftemp > 2) && (difftemp < 20)) {
    digitalWrite(blueled, LOW);
    digitalWrite(greenled, HIGH);
    digitalWrite(yellowled, LOW);
  }
  if (difftemp > 22) {
    digitalWrite(blueled, LOW);
    digitalWrite(greenled, LOW);
    digitalWrite(yellowled, HIGH);
  }
  delay(100);
}

It worked well and I can see some definite applications (e.g. is my module overheating!)

Some news as well in this video - we are moving house after 7 years. It is just down a road a bit, but the packing up and unpacking of the lab will take a few weeks.

If I get a moment I will try to post a video or two - but I might also go a bit "dark" over the Tasmanian winter.

Apologies if you have just joined the channel and blog - I hope the back catalogue of 200 videos can keep you busy while I rearrange my life!

Take care and see you on the other side.



Friday, May 12, 2023

0000 0000 1100 1001

200 videos - no way!

Nearly four years ago I started (belatedly) a blog and YT channel in order to bring some semblance of order to the chaos of my online electronics shopping addiction!

Some of the projects have been educative (for me!), some dismal failures (the great ferrules disaster of 2022), some excellent solutions for issues around the house (lighting, timing and temperature) and all of them a privilege and a joy.

They are all my children and of course I'm not supposed to have favourites, but I have cobbled together a 5+2 "best of" for the video below.

Thank you for your company on this journey - and I hope you'll stick around for the next 200! <gulp>



Friday, May 5, 2023

0000 0000 1100 1000

The Dirty Dozen - Part Five - 3 axes accelerometer as Fall Detector

Those of us who fall off things may want immediate help or maybe even notifications sent to relevant authorities. Perhaps you have a relative or friend, prone to falling, who needs some gentle silicon monitoring?

The LIS3DH Triaxial Acceleration Temperature Sensor might be just the ticket. When I pulled it out of the Dirty Dozen box I thought immediately that if I could talk to the thing and get some sense out of it then I'd take a crack at a fall detector.

The theory is that if there is sudden acceleration of the module (or the object in which it is contained) then the device would output, in three dimensions, the magnitude of that "overall" event.

To characterise it as a single event I thought I might use a virtual 3D box and plot values from the ideal position (no acceleration for zero) to a calculated threshold value (found in my case by experimentation).


That High School math sure does come in handy some days!

I went looking for all sorts of information on this module only to discover that I think it's a cheap knockoff of an existing product (surprise!).

Using a fair amount of optomistic pixie dust I sprinkled in some code from the legitimate product found here at this link.

After successfully "talking" to the module with the legit code and library, I then embarked upon coding the fake version. It took a bit longer than expected as my perfection gene kicked in halfway through the coding process.

/*
   based on code by Marshall Taylor @ SparkFun Electronics
   https://github.com/sparkfun/LIS3DH_Breakout
   https://github.com/sparkfun/SparkFun_LIS3DH_Arduino_Library

   OneCircuit https://www.youtube.com/@onecircuit-as
   Tue 18 Apr 2023 14:03:27 AEST
*/

#include "SparkFunLIS3DH.h"
#include "Wire.h"
#include "SPI.h"

#define alarmLED 4

float xmove = 0;
float ymove = 0;
float zmove = 0;
float falldetect = 0;   // how hard is fall?
boolean fell = false;
float biggestfall = 0;
int falltrigger = 300;  // how hard to fall?
long timer = 0;
long currenttime = 0;
long bigfalltime = 5000;
LIS3DH myIMU(I2C_MODE, 0x19);

void setup() {
  Serial.begin(57600);
  pinMode(alarmLED, OUTPUT);

  myIMU.settings.adcEnabled = 1;
  myIMU.settings.tempEnabled = 0;
  // in Hz: 0,1,10,25,50,100,200,400,1600,5000
  myIMU.settings.accelSampleRate = 200;
  // Max G force: 2, 4, 8, 16
  myIMU.settings.accelRange = 16;
  myIMU.settings.xAccelEnabled = 1;
  myIMU.settings.yAccelEnabled = 1;
  myIMU.settings.zAccelEnabled = 1;

  myIMU.begin();
  delay(1000); // settle petal

}

// here is where you would txt, email or call for help
void raisealarm() {
  digitalWrite(alarmLED, HIGH);
  fell = true;
  timer = millis();
}

void loop()
{
  // time at start of loop
  currenttime = millis();

  // measure and convert each axis
  xmove = abs(myIMU.readFloatAccelX() * 100);
  ymove = abs(myIMU.readFloatAccelY() * 100) - 5;
  zmove = abs(myIMU.readFloatAccelZ() * 100) - 93;

  // has the device fallen?
  falldetect = sqrt(xmove * xmove + ymove * ymove + zmove * zmove);
  if (falldetect > falltrigger) {
    raisealarm();
  }

  Serial.print(xmove);
  Serial.print(",");
  Serial.print(ymove);
  Serial.print(",");
  Serial.print(zmove);
  Serial.print(",");
  Serial.print(falldetect);
  Serial.print(",");
  Serial.println(biggestfall);

  if (falldetect > biggestfall) {
    biggestfall = falldetect;
  }

  if (((currenttime - timer) > bigfalltime) && fell) {
    digitalWrite(alarmLED, LOW);
    fell = false;
    biggestfall = 0;
    timer = 0;
  }

  delay(20);
}

The results were, I don't mind saying, pretty impressive! I'd like to maybe further develop this project to include an "IoT" twist - such that maybe fall detection is accompanied by a text or email message.

Your thoughts, as always, appreciated!



Thursday, April 27, 2023

0000 0000 1100 0111

Two out of three ain't bad

Recently an LED in the house went dark, and usually I'd just throw it out and replace it. This time I thought it was a bit rude as the bulb is nominally rated 30000 hours and it had only been in for around 100 hours.


Two possibilities:

1. The bulb was not up to spec

2. The variations in AC voltage at our place was too much for it

Either way I could see some clear marks from a possible short, and so I wanted to open it up and take a look.

The result is a little bit of a boring video, but nonetheless "illuminating". Also, breaking into the device was a bit of a laugh.


Friday, April 21, 2023

0000 0000 1100 0110

The Dirty Dozen - Part Four - unreachable exotica

I saw a beautiful shiny bauble in the online shop that turned out to be unobtainium! 

Recently Great Scott did an AliExpress based video where he was trawling through Chinese datasheets trying to gain access to a particular piece of hardware.

Oh, Great Scott - how much time I have wasted in this exact same situation!

Case in point, a lovely looking Air105 based module. Would I have bought it in hindsight? Yes! Who doesn't like unobtainium and unicorns??

For around $5 I received a very impressive module AND a camera to suit. Yummy!

And look at those specs!

Of course, unicorns may fly very fast, but first you have to catch one and communicate with it - not so easy!

The main issues for me revolved around having to:

1. learn a new programming language to talk to this thing (lua) as well as,

2. installing Windows (when I use Linux exclusively) and finally,

3. the majority of the support/software is Chinese based as well!

After much faffing about and grumbling I had to eventually concede defeat. I am going to check in from time to time to see if some geniuses have made this lovely piece of hardware accessible for dumbos like myself (e.g. via an Arduino IDE based library)

Until then - I'll enjoy looking at it.




Thursday, April 13, 2023

0000 0000 1100 0101

Mailbag #30

A testament to late night ordering is the arrival of not one, but two idiotic purchases - AC direct LEDs!

I'm very unlikely to want to fry myself with that nonsense, so they'll go straight to the bottom drawer.

In a few decades time one of my descendants will find them and shake their head at my hubris.

In the meantime you can shake your head at my hubris AND see some other useful stuff that arrived around the same time.

Enjoy the mailbag!



Friday, April 7, 2023

0000 0000 1100 0100

Unoffical safety car

Recently I was basking in the noise and fragrance of World Superbikes when I noticed some flashing lights. Atop the safety cars were red repeater lights and I started to wonder if that could be reproduced using a breadboard and a 555 timer.

It turns out that two 555 timers are required and that is exactly what is in a 556 IC.

I modelled the circuit using two 555 chips because of the limitations of the software, but built it using a 556 as seen below.



Apart from a little hiccup involving some missing links between trigger and threshold, the circuit works really well, exactly as simulated.

In fact, I attached it to an actual car for that final dash of realism to compare it to the original safety car footage from Phillip Island!