Dec 10, 2020

[Arduino code] Proportional-Integral-Differential control (PID control)

- Supplies: Arduino board, ... sensor, ... actuator

- Comment: I use 'AutoPID' library and this code is based on the bottom *site.

*https://r-downing.github.io/AutoPID/

- How to install a PID library?

Sketch-> Include Library -> Manage Libraries... -> Write 'pid'


- Example code:

#include <AutoPID.h>

#define p_gain 1
#define i_gain 1
#define d_gain 1

//Min and Max values depend on your actuator function code. 
#define control_input_min -255
#define control_input_max 255

// unit: milliseconds
// ex) 20 ms => 50 Hz
#define control_interval 20 

double measured_value, desired_value, control_input, value_from_sensor;

AutoPID PID_control(&measured_value, &desired_value, &control_input, control_input_min, ...,
control_input_max, p_gain, i_gain, d_gain);
void setup() {
  // put your setup code here, to run once:
  PID_control.setTimeStep(control_interval);
}

void loop() {
  // put your main code here, to run repeatedly:

  desired_value = 0; //It depends on your tasks.
  measured_value = value_from_sensor; //It is measured by sensor, so its type depends on your sensor.
  PID_control.run();
  //Then, 'control_input' is calculated and its value drives your actuators.
  //So, you need to insert your actuator function code to the bottom side.
  //ex) move(1, 1, control_input);
  
}


Dec 8, 2020

[Arduino code] 9-axis IMU sensor MPU-9250 (9축 IMU 센서)

- Supplies: *IMU sensor (MPU-9250), Arduino board

* https://learn.sparkfun.com/tutorials/mpu-9250-hookup-guide/all

- How to connect?!



- Example code: The bottom code is based on the *Sparkfun-site and I revised the original code as a simple version.

#include "quaternionFilters.h"
#include "MPU9250.h"

#define AHRS true         // Set to false for basic data read
#define SerialDebug true  // Set to true to get Serial output for debugging

// Pin definitions
int intPin = 12;  // These can be changed, 2 and 3 are the Arduinos ext int pins
int myLed  = 13;  // Set up pin 13 led for toggling

#define I2Cclock 400000
#define I2Cport Wire
// Use either this line or the next to select which I2C address your device is using
#define MPU9250_ADDRESS MPU9250_ADDRESS_AD0   
//#define MPU9250_ADDRESS MPU9250_ADDRESS_AD1 MPU9250 myIMU(MPU9250_ADDRESS, I2Cport, I2Cclock); #define measure_period 100 //1000ms = 1sec unsigned long current_time; void setup() { Wire.begin(); // TWBR = 12; // 400 kbit/sec I2C speed Serial.begin(38400); while(!Serial){}; // Set up the interrupt pin, its set as active high, push-pull pinMode(intPin, INPUT); digitalWrite(intPin, LOW); pinMode(myLed, OUTPUT); digitalWrite(myLed, HIGH); // Read the WHO_AM_I register, this is a good test of communication byte c = myIMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); Serial.print(F("MPU9250 I AM 0x")); Serial.print(c, HEX); Serial.print(F(" I should be 0x")); Serial.println(0x71, HEX);

Dec 7, 2020

Lithium polymer battery charger module (TP4056) schematic and board using Eagle PCB software (AUTODESK) (PCB 설계 소프트웨어 EAGLE을 활용한 리튬폴리머 배터리 충전 모듈 (TP4056) 회로도 및 보드)

*If you need some design files or materials, please ask me.

- Board: Lipo. battery charger module (TP4056)

- PCB software: Eagle (AUTODESK)

- Bills of material (BOM)

Schematic

(Left) Board, (right) Virtual image

Dec 1, 2020

[Arduino code] Express number using FND display module TM1637 (디스플레이 모듈을 이용한 숫자 표기)

- Supplies: *FND display (SZH-EKBZ-016), Arduino board
- 준비물: FND 디스플레이, 아두이노

*https://www.devicemart.co.kr/goods/view?no=1326952

#include <TM1637Display.h>

#define baud_rate 9600
#define CLK 9
#define DIO 10


TM1637Display dsp(CLK, DIO);

void setup() {
  Serial.begin(baud_rate);
  Serial.println("Serial Start");

}

void loop() {

  dsp.setBrightness(5); // brightness: 0 ~ 7
  double number = 123;  
//  dsp.showNumberDec(number); 
//  dsp.showNumberDec(number, true); 
//  dsp.showNumberDecEx(number, 0x40);
//  dsp.showNumberDecEx(number, 0x40, true);
  
}



Top left: dsp.showNumberDec(number);  Top right: dsp.showNumberDec(number, true);
Bottom left: dsp.showNumberDecEx(number, 0x40);, Bottom right: dsp.showNumberDecEx(number, 0x40, true);