This is a draft and maybe it become a book and / with helper.

DIY-IT

edit

Preface

edit

Motivation

The sites, books, magazines with DIY-Maker-IT are countless. In result of other important issues in the real world, company changes and so on, the timeliness can be better. Sometime we can work content 1:1 and it runs, but a community in my opinion can it better as one person.

For example the german C´t Make magazine "ESP32 special" from 2019 comes with hardware ESP32 and articles how to use it. Of course this works also 2023 but we need modify some steps, change URLs who doesn't exist and so on.

Restriction This book doesn't restrict to microprocessor or single board computers because take ever the hardware who best performs for your solution. In result of my problem I switch between Raspberry Pi, ESP32 and also Mac and also between different operating systems.

The second reason is that sensor, motors and other secondary hardware is working with more than one platform.


Part I

edit

My recommendation: first make it easy, take tools, hardware and software that works with a community.

Hardware

edit

Hardware for DIY-IT can be from micro computer to single computer board (SCB) like ESP32 to Raspberry Pi and others. If you see a GPIO in the hardware specification you are right here, but also other hardware can identify DIY-Hardware.

If microprocessor hardware is your target you need a "second" computer to programming, compile and transfer you programs. On SCB you should have a second computer because software do what you program not what you want.


Software

edit

If you have a single board computer you can coding directly on your system. Take your favorite IDE or text editor and compiler.

With micro processor you need also this and in extension a transfer program. Some IDE include the transfer like Arduino IDE.


Programming language

edit

Not only one programming language can be the right choice.

If you have hardware a closer look into specification can help. Mostly C, Assembler or Python is working. But in some case you can also be free or you need to learn one specific programming language.

If you want to start choose your hardware from view of your favorite programming language.

I don't recommend C because it's easy, but because it works almost every time and helps programming from microprocessor to GPU. But be aware you can take different.

Part II - projects

edit

In different to Part I this section is to take you on a journey to a specific project.


compass application

edit

This simple compass application is explain how to create a digital compass. This sample use the QMC5883LCompass library without temperature sensor support.

Hardware Software
ESP-WROOM-32 Arduino IDE 2.1
GY-271 QMC5883LCompass 1.1.1


#include <QMC5883LCompass.h>
QMC5883LCompass compass;

// the setup of hardware
void setup() {
  Serial.begin(115200); // set the serial speed to board specific rate
  compass.init(); // initialize the compass sensor

  delay (5000);
}

// the application loop
void loop () {

  compass.read(); // read compass sensor values
  byte a = compass.getAzimuth();
  // Return Azimuth reading
  Serial.print("Azimuth: ");
  Serial.println(a);

  byte d = compass.getBearing(a);
  // Output is a value from 0 - 15
  // based on the direction of the bearing / azimuth   
  Serial.print("Direction: ");
  Serial.println(d);
  
  // the direction is stored on given array of char
  char compassLetters[3]; 
  compass.getDirection(compassLetters, a); 
  Serial.print(compassLetters[0]); 
  Serial.print(compassLetters[1]); 
  Serial.println(compassLetters[2]);

  delay(1000);
}

temperature measures

edit

Next simple application shows how to measure different temperature values:

  • onboard temperature sensor, the processor heat
  • GY-271 temperature sensor, only changes of temperature
  • KY-015 temperature module, external real temperature sensor

onboard temperature

edit

temperature changes with GY-271 (QMC5883L)

edit

Other than compass application sample follow source code works more low code than API centric.

// init the function to read the sensor data
#include <Wire.h>
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif

uint8_t temprature_sens_read();


#define QMC5883L_I2C_ADDRESS   0x0D // define the I2C address to default of this sensor

#define QMC5883L_REG_CTRL1     0x09  // control register 1
#define QMC5883L_REG_PERIOD    0x0B  // SET/RESET period register
#define QMC5883L_REG_DOUTLSB   0x00  // data output X LSB register
#define QMC5883L_REG_TEMP      0x07  // temperature sensor output

// configuration

#define QMC5883L_CFG_DEFAULT   0x1D // look at hardware specification datasheet: 0x1D --> 00 01 11 01 --> OSR = 512, RNG = 8G, ODR = 200Hz, Mode = Continuous
#define QMC5883L_CFG_PERIOD    0x01 // recommended in datasheet

void setup() {
  Serial.begin(115200); // set the serial speed to board specific rate
  // configure the hardware
  Wire.begin();

  Wire.beginTransmission(QMC5883L_I2C_ADDRESS);
  Wire.write(QMC5883L_REG_CTRL1);
  Wire.write(QMC5883L_CFG_DEFAULT);
  Wire.endTransmission();

  Wire.beginTransmission(QMC5883L_I2C_ADDRESS);
  Wire.write(QMC5883L_REG_PERIOD);
  Wire.write(QMC5883L_CFG_PERIOD);
  Wire.endTransmission();

}

void loop() {
  int16_t temperature = -273.16; // set a random default value

  // explain we want the temperature sensor output from I2C connected part
  Wire.beginTransmission(QMC5883L_I2C_ADDRESS);
  Wire.write(QMC5883L_REG_TEMP);
  Wire.endTransmission();

  // get the data if available
  Wire.requestFrom(QMC5883L_I2C_ADDRESS, 2);
  if (Wire.available() == 2) {
    temperature  = Wire.read();      // LSB t
    temperature |= Wire.read() << 8; // MSB t
  }
  temperature = (temperature / 100.0) ;

  Serial.print("temp (ext): ");
  Serial.println (temperature);

  delay(1000);
}

external temperature sensor with KY-015 (DHT-11)

edit

The KY-015 contains a DHT-11 sensor. Other than example above next source code read the real temperature. This sensor can be have different labels for pins. Be sure + is the power, - is the ground and the other pin is for data, on board Hera is labeling with "out". Also the positions of pins can be different.


The example is using the DHT sensor library by Adafruit and the dependency Adafruit Unified sensor.

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN 15 // in result of GPIO 15 on my ESP32 board is near by power and ground I use this
#define DHTTYPE DHT11 // DHT11 is defined, because this is my sensor

DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200); // set the serial speed to board specific rate
  dht.begin();

  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  Serial.println(sensor.name);
  Serial.println(sensor.max_value);
}

void loop() {
  sensors_event_t event; // our sensor send events
  dht.temperature().getEvent(&event);

  if (isnan(event.temperature)) { // if no temperature is coming from sensor
    Serial.println ("error"); // maybe you see it on first reading
  }
  else {
    Serial.print(F("Temperature: "));
    Serial.print (event.temperature);
    Serial.println (" C");
  }

  delay(5000);
}


Appendix - Hardware

edit

This is the section for project specific hardware.

GY-271 - Compass

edit

The GY-271 is a compass magnetic module with QMC5883L chip. It contains also a 16-bit temperature sensor, but this temperature sensor is not factory-calibrated and so can only measure temperature changes.

GY-271
parameter values details
power voltage range 3.3 - 5V
power consume 75 μA
communication interface I2C 0x0D (default)
dimension 13x14x3 mm without header
weight <1 g without header
library QMC5883LCompass 1.1.1 tested for magnetic compass
library none (Wire) tested for temperature changes

Connections (based on my local hardware ):

  • VCC to power
  • GND to ground
  • SCL to I2C SCL
  • SDA to I2C SDA

Projects:

  • compass application
  • temperature measure (only changes)

KY-015 - Temperature

edit

The KY-015 is a temperature module with DHT11 chip.

KY-015
parameter values details
power voltage range 3.3 - 5V
power consume unknown
communication interface GPIO
dimension 29x14x7 mm without header
weight 2 g with header
library DHT sensor library 1.4.4 from Adadfriut, tested for temperature

Connections (based on my local hardware ):

  • + to power
  • - to ground
  • OUT to GPIO

Projects:

  • temperature measure