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.



No comments:

Post a Comment