Professional Documents
Culture Documents
51099 36
04-8325434
04-8325434
tyc6095@ms1.hinet.net
102 8
600
ISBN
9789868936027
Windows/Mac
51099 36
04-8325434
2D
PDF Reader
tyc6095@ms1.hinet.net
~1~
Arduino
Arduino
idea
Arduino
Arduino
Arduino
Arduino
~2~
follow
~3~
2013
(ICT)
ICT
Arduino
Arduino
Arduino
Arduino
ICT
DIY(Do It Yourself)
~4~
Arduino
2013
~5~
........................................................................................................................2
........................................................................................................................4
......................................................................................................................6
....................................................................................................................9
..................................................................................................................11
......................................................................................................13
Arduino .................................................................................................16
Arduino ..............................................................................................16
Arduino ...............................................................................................18
Arduino ...............................................................................19
......................................................................................................22
..............................................................................................................26
..............................................................................................................27
......................................................................................................31
......................................................................................................33
......................................................................................................39
......................................................................................43
......................................................................................................47
......................................................................................................49
......................................................................................................54
......................................................................................................55
~6~
......................................................................................................60
..............................................................................................................62
......................................................................................62
......................................................................................................65
..........................................................................................................67
Strain gauge .........................................................70
Strain gauge .............................................................................72
..............................................................................................73
......................................................................................................76
Analog to Digital Coverters (ADC) .................................................78
Analog to Digital Converters ......................................................78
/A/D..............................................84
......................................................................................................97
..............................................................................................................99
..................................................................................99
............................................................................106
........................................................113
....................................................................................................116
............................................................................................................118
....................................................................118
....................................................................120
LCD ...................................................................................................122
LCD KeyPad Shield ....................................................................................130
~7~
LCD ......................................................................135
....................................................................................................140
............................................................................................................142
........................................................................................142
............................................................................................143
....................................................................................................144
........................................................................148
................................................................................154
Arduino .....................................................................................159
........................................................162
....................................................................................................168
............................................................................................................170
....................................................................................................................171
HX711 Arduino .............................................................................171
LCD 1602 .....................................................................................175
LCD&Keypad Shield ...................................................................189
DS1307 .........................................................................................195
HX711 ......................................................................................202
LCDKeypad Shield ...............................................................211
LCM 1602 ................................................................................212
............................................................................................................228
~8~
1 Arduino Duemilanove ...............................................20
2 Arduino UNO ............................................................21
3 Arduino Mega2560 ...................................................22
4 ............................................................................................62
5 .........................................................................69
6 ............................................................................69
7 ........................................................................70
8 ........................................................................................73
9 ........................................................................................74
10 .......................................................75
11 HX711 ADC .........................................................................78
12 HX711 ADC .................................................................79
13 AD ......................................................82
14 A 128db .......................................................................83
15 HX711 ........................................84
16 HX711 ..........................................................................86
17 HX711 SOP-16 ....................................................................86
18 HX711 ..................................................................................94
19 HX711 ......................................................................95
20 HX711 ..................................................................96
21 ....................................................................101
22 ()..................................................102
23 100 .............................................................102
~9~
24 ( 100 )..........................................103
25 500 .............................................................104
26 ( 500 )..........................................105
27 ....................................................................107
28 ()......................................108
29 100 .................................109
30 ( 100 )......................109
31 500 .................................110
32 ( 500 )...................... 111
33 ADC .................................................112
34 ............................................................113
35 ............................................116
36 ........................................................118
37 LCD1602 ...............................................................................123
38 LCD 1602 ...................................................................125
39 LCD 1602 ...........................................................................125
40 LCD Keypad Shield........................................................................131
41 LCD Keypad Shield PCB Layout ...........................................132
42 keypadshield ..................................................................135
43 ........................................................140
44 USB TTL ..........................................................................153
45 ............................................................153
46 .....................................................159
47 Tiny RTC I2C ................................................................160
48 ............................168
~ 10 ~
1 ................................................................................49
2 HX711 SOP-16 ()....................................................87
3 HX711 SOP-16 ..............................................................88
4 HX711 () ................................................................89
5 HX711 ...........................................................................90
6 A/D ........................................................93
7 HX711 ....................................................................................94
8 HX711 ..............................................99
9 HX711 Arduino ...........................................100
10 ()..............................................................101
11 ( 100 ) ......................................................103
12 ( 500 )......................................................104
13 ()..............................................107
14 ( 100 )......................................109
15 ( 500 )..................................110
16 ............................................................................112
17 ....................................................................114
18 .....................................................115
19 ....................................119
20 HX711 Arduino ..................................................................120
21 ................................................................121
22 LCD1602 ...................................................................123
~ 11 ~
~ 12 ~
~ 13 ~
Arduino C
~ 14 ~
Arduino
~ 15 ~
Arduino
Arduino
Massimo Banzi Ivrea
2005 Massimo Banzi
David Cuartielles David Cuartielles
Arduino
BanziCuartielles Mellis
(Open Source)
CC (Creative_Commons, 2013)
CC(Creative_Commons, 2013)
GPL1license
2 (Free Software Foundation)
GNU (GNU GPL) CC
~ 16 ~
Arduino
Arduino
CC Arduino
Arduino Arduino 3
Arduino
Arduino (Arduino, 2013)
ArduinoMassimo BanziDavid Cuartielles
Tom IgoeGianluca MartinoDavid Mellis Nicholas Zambetti(Arduino,
2013) Arduino Arduino
http://www.arduino.cc/
Arduino
Atmel
AVR
(Atmel_Corporation, 2013)
Simple I/O Java C
Processing 4 /Wiring (Reas, 2013, Reas and Fry, 2007, Reas and Fry,
2010)Processing MIT (Aesthetics & Computation
Group) Ben Fry(http://benfry.com/) Casey Reas Processing
Open Source
Arduino Arduino
~ 17 ~
SwitchLED
Arduino IDE
(Banzi, 2009)
Arduino
http://www.arduino.cc/!!
(http://www.arduino.cc/) Arduino
(,,,
,,)
(ATMEGA8-16)
USB 9VDC
ArduinoCCD
~ 18 ~
Arduino
Duemilanove
:USB
: ATMEGA328
USB/
ATmega328
5V
(recommended)7-12 V
(limits)6-20 V
bootloader5
Arduino
Arduino USB
boot loader
~ 19 ~
1 Arduino Duemilanove
UNO
ATMega 8U2 USB- ICSP
MEGA8U2 ~ FTDI
USB ~ Arduino IC 3.3V
ATmega328
5V
(recommended)7-12 V
(limits)6-20 V
I/O Pins14 (of which 6 provide PWM output)
Pins6
DC Current per I/O Pin40 mA
DC Current for 3.3V Pin50 mA
Flash Memory32 KB (of which 0.5 KB used by bootloader)
SRAM2 KB
EEPROM1 KB
Clock Speed16 MHz
~ 20 ~
2 Arduino UNO
MEGA2560
Arduino
ATmega2560
5V
(recommended)7-12 V
(limits)6-20 V
I/O Pins54 (of which 14 provide PWM output)
UART:4
Pins16
DC Current per I/O Pin40 mA
DC Current for 3.3V Pin50 mA
Flash Memory256 KB of which 8 KB used by bootloader
SRAM8 KB
EEPROM4 KB
Clock Speed16 MHz
~ 21 ~
3 Arduino Mega2560
Arduino
Language Reference (http://arduino.cc/en/Reference/HomePage)
Arduino
setup()
loop()
Arduino (SKETCH)
~ 22 ~
void setup()
Arduino -
(loop()) Arduino pin
void loop()
Arduino
Arduino
(block structure)
C {}
C
(Compound Statement)
(
) (CPU
)
~ 23 ~
(naming space)
C (naming space)
(local variable) ()
int
z
{
int x, r;
x=10;
r=20;
{
int y, z;
float r;
y = x;
x = 1;
r = 10.5;
}
z = x; // z
}
r
(scope)
(Lifetime)
~ 24 ~
r r float
C
{
int tmp;
for (tmp=0; tmp<1000; tmp++)
doSomeThing();
}
{
float tmp;
tmp = y;
y = x;
x = y;
}
tmp
tmp
; (semicolon)
{} (curly braces)
// (single line comment)
/* */ (multi-line comment)
Arduino
~ 25 ~
; //()
Arduino
delay(100);
{}()
loop()
void loop(){
Serial.pritln("Hello !! Welcome to Arduino world");
}
(
)
Arduino
Arduino
~ 26 ~
//
/*
*/
(identifier) C
(declaration)
HIGH | LOW
INPUT | OUTPUT
true | false
Integer Constants
~ 27 ~
boolean
char
byte
int
unsigned int
long
unsigned long
float
double
string
array
void
Arduino
Arduino
Arduino :
boolean
~ 28 ~
(true)(false)
char
A Arduino
-128 127
PS ASCII UNICODE
ASCII 127
UNICODE
ASCII
byte
0 255
(8 )
int
2 32,768
32,767; Arduino
unsigned int
2
0 65,535
~ 29 ~
long
2,147,483,648 2,147,483,647
unsigned long
0 4,294,967,295
float
RAM
double
1.7976931348623157 x 10308
string
ASCII (
)
Ardunio
array
LED
light01light02light03light04light05light06
"array" []{}
char()
byte()
int()
long()
float()
char()
char(x)
x:
byte()
byte(x)
x:
~ 31 ~
int(x)
int(x)
x:
long()
int(x)
x:
float()
float(x)
~ 32 ~
x:
if
if...else
for
switch case
while
do... while
break
continue
return
Ardunio
if else
If (expression)
else .
if else
~ 33 ~
#define LED 12
void setup()
{
int val =1;
if (val == 1) {
digitalWrite(LED,HIGH);
}
}
void loop()
{
}
for
void setup()
{
for (int i = 1; i < 9; i++) {
Serial.print("2 * ");
Serial.print(i);
Serial.print(" = ");
Serial.print(2*i);
}
}
void loop()
{
}
switch case
~ 34 ~
while
while
:
void setup()
{
~ 35 ~
int sensorValue;
// sensor 256 LED 1
sensorValue = analogRead(1);
while (sensorValue < 256) {
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,HIGH);
delay(100);
sensorValue = analogRead(1);
}
}
void loop()
{
}
do while
while while
dowhile
:
void setup()
{
int sensorValue;
do
{
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,HIGH);
delay(100);
sensorValue = analogRead(1);
}
while (sensorValue < 256);
}
void loop()
~ 36 ~
{
}
break
Break
break switch case
:
void setup()
{
}
void loop()
{
int sensorValue;
do {
//
if (digitalRead(7) == HIGH)
break;
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,HIGH);
delay(100);
sensorValue = analogRead(1);
}
while (sensorValue < 512);
}
continue
continue
~ 37 ~
:
#define PWMpin 12
#define Sensorpin 8
void setup()
{
}
void loop()
{
int light;
int x ;
for (light = 0; light < 255; light++)
{
// 140 200
x = analogRead(Sensorpin) ;
if ((x > 140) && (x < 200))
continue;
analogWrite(PWMpin, light);
delay(10);
}
}
return
return
computeTemperature()
temperature
#define PWMpin 12
#define Sensorpin 8
void setup()
{
~ 38 ~
}
void loop()
{
int light;
int x ;
for (light = 0; light < 255; light++)
{
// 140 200
x = computeTemperature() ;
if ((x > 140) && (x < 200))
continue;
analogWrite(PWMpin, light);
delay(10);
}
}
int computeTemperature() {
int temperature = 0;
temperature = (analogRead(Sensorpin) + 45) / 100;
return temperature;
}
= ()
+ ()
- ()
* ()
~ 39 ~
/ ()
% ()
Arduino +
* /
(%)
()
:
#define PWMpin 12
#define Sensorpin 8
void setup()
{
int sensorValue;
int light;
int remainder;
sensorValue = analogRead(Sensorpin) ;
light = ((12 * sensorValue) - 5 ) / 2;
remainder = 3 % 2;
}
void loop()
{
}
== ()
~ 40 ~
!= ()
< ()
> ()
<= ()
>= ()
if,while, for
==
a==1
!=
a!=1
<
a<1
>
a>1
<=
a<=1
>=
a>=1
&& (and)
|| (or)
! (not)
5 10
#define PWMpin 12
#define Sensorpin 8
void setup()
{
~ 41 ~
}
void loop()
{
int light;
int sensor ;
for (light = 0; light < 255; light++)
{
// 140 200
sensor = analogRead(Sensorpin) ;
if ((sensor >= 5) && (sensor <=10))
continue;
analogWrite(PWMpin, light);
delay(10);
}
}
1:
Int value = 10 ;
value = value + 1 ;
(++)
Int value = 10 ;
value ++;
~ 42 ~
++ (increment)
-- (decrement)
+= (compound addition)
-= (compound subtraction)
*= (compound multiplication)
/= (compound division)
(++ --)
1 1 i++++i
i++i i i+1++i i
i i 1
+= , =, *= and /=
Int value = 10 ;
value = value +5 ;
value += 5 ;
// ()
// ()
pinMode()
digitalWrite()
digitalRead()
analogRead()
~ 43 ~
analogWrite() - PWM
Arduino
pinMode(pin, mode)
(digital pin)
#define sensorPin 7
#define PWNPin 8
void setup()
{
pinMode(sensorPin,INPUT); // sensorPin (7)
}
void loop()
{
}
:
digitalWrite(pin, value)
pinMode
digitalWrite
:
#define PWNPin 8
#define sensorPin 7
void setup()
{
digitalWrite (PWNPin,OUTPUT); // PWNPin (8)
}
void loop()
~ 44 ~
{}
int digitalRead(pin)
HIGH
LOW
:
#define PWNPin 8
#define sensorPin 7
void setup()
{
pinMode(sensorPin,INPUT); // sensorPin (7)
val = digitalRead(7); // 7 val
}
void loop()
{
}
int analogRead(pin)
0 1023 0 5
:
#define PWNPin 8
#define sensorPin 7
void setup()
{
pinMode(sensorPin,INPUT); // sensorPin (7)
val = analogRead (7); // 7 val
}
void loop()
{
~ 45 ~
analogWrite(pin, value)
PWM 356910 11value
0-255 2.5 V 128
:
#define PWNPin 8
#define sensorPin 7
void setup()
{
analogWrite (PWNPin,OUTPUT); // PWNPin (8)
}
void loop()
{
}
I/O
tone()
noTone()
shiftOut()
pulseIn()
bitOrder LSBFIRST
MSBFIRST value byte
:
~ 46 ~
#define dataPin 8
#define clockPin 7
void setup()
{
shiftOut(dataPin, clockPin, LSBFIRST, 255);
}
void loop()
{
}
:
#define dataPin 8
#define pulsein 7
void setup()
{
Int time ;
time = pulsein(pulsein,HIGH); // 7
HIGH
}
void loop()
{
}
millis()
micros()
delay()
delayMicroseconds()
~ 47 ~
:
int lastTime ,duration;
void setup()
{
lastTime = millis() ;
}
void loop()
{
duration = -lastTime; // "lastTime"
}
delay(ms)
:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(millis()) ;
delay(500); //500
}
10 3 10 3
0.001 1
~ 48 ~
pico
10 12
nano
10 9
micro
10 6
milli
10 3
kilo
10 3
mega
10 6
giga
10 9
tera
tera
delay Microseconds(us)
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(millis()) ;
delayMicroseconds (1000); //500
min()
max()
abs()
constrain()
~ 49 ~
map()
pow()
sq()
sqrt()
min(x, y)
#define sensorPin1 7
#define sensorPin2 8
void setup()
{
int val;
pinMode(sensorPin1,INPUT); // sensorPin1 (7)
pinMode(sensorPin2,INPUT); // sensorPin2 (8)
val = min(analogRead (sensorPin1), analogRead (sensorPin2)) ;
}
void loop()
{
}
max(x, y)
#define sensorPin1 7
#define sensorPin2 8
void setup()
{
int val;
pinMode(sensorPin1,INPUT); // sensorPin1 (7)
pinMode(sensorPin2,INPUT); // sensorPin2 (8)
val = max (analogRead (sensorPin1), analogRead (sensorPin2)) ;
~ 50 ~
}
void loop()
{
}
abs(x)
#define sensorPin1 7
void setup()
{
int val;
pinMode(sensorPin1,INPUT); // sensorPin (7)
val = abs(analogRead (sensorPin1)-500);
// -500
}
void loop()
{
}
constrain(x, a, b)
x a b x a a a b
x b b
#define sensorPin1 7
#define sensorPin2 8
#define sensorPin 12
void setup()
{
int val;
pinMode(sensorPin1,INPUT); // sensorPin1 (7)
pinMode(sensorPin2,INPUT); // sensorPin2 (8)
~ 51 ~
#define sensorPin1 7
#define sensorPin2 8
#define sensorPin 12
void setup()
{
int val;
pinMode(sensorPin1,INPUT); // sensorPin1 (7)
pinMode(sensorPin2,INPUT); // sensorPin2 (8)
pinMode(sensorPin,INPUT); // sensorPin (12)
val = map(analogRead(sensorPin), analogRead (sensorPin1), analogRead
(sensorPin2),0,100) ;
// analog0 100 200
}
void loop()
{
}
~ 52 ~
int y=2;
double x = pow(y, 32); // x y 32
double sqrt(x)
double
int y=2123;
double x = sqrt (y); // 2123
sin()
cos()
tan()
double sin(rad)
radians sine
int y=45;
double sine = sin (y);
// 0.70710678118654
double cos(rad)
radians cosine
int y=45;
~ 53 ~
double tan(rad)
radians tangent
int y=45;
double tangent = tan (y);
// 1
randomSeed()
random()
randomSeed(seed)
Arduino
#define sensorPin 7
void setup()
{
randomSeed(analogRead(sensorPin)); //
}
void loop()
{
~ 54 ~
long random(max)
long random(min, max)
long 0
#define sensorPin 7
long randNumber;
void setup(){
Serial.begin(9600);
// if analog input pin sensorPin(7) is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(sensorPin));
}
void loop() {
// print a random number from 0 to 299
randNumber = random(300);
Serial.println(randNumber);
// print a random number from 0 to 100
randNumber = random(0, 100); // 0 99
Serial.println(randNumber);
delay(50);
}
~ 55 ~
Serial.begin(speed)
Arduino 9600 bps
115,200 bps
void setup() {
Serial.begin(9600);
}
void loop() {
}
Serial.print(data)
int x = 0;
// variable
void setup() {
Serial.begin(9600);
}
void loop() {
// print labels
Serial.print("NO FORMAT");
Serial.print("\t");
Serial.print("DEC");
Serial.print("\t");
Serial.print("HEX");
// prints a label
// prints a tab
Serial.print("\t");
Serial.print("OCT");
Serial.print("\t");
Serial.print("BIN");
~ 56 ~
Serial.print("\t");
}
Serial.println(data)
Serial.println(data, encoding)
Serial.print()
Enter
int x = 0;
// variable
void setup() {
Serial.begin(9600);
}
void loop() {
// print labels
Serial.print("NO FORMAT");
Serial.print("\t");
Serial.print("DEC");
Serial.print("\t");
Serial.print("HEX");
Serial.print("\t");
Serial.print("OCT");
Serial.print("\t");
Serial.print("BIN");
Serial.print("\t");
// prints a label
// prints a tab
int Serial.available()
bytes read()
0 read()
int Serial.read()
1byte
~ 58 ~
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600);
// opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
int Serial.write()
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.write(45); // send a byte with the value 45
int bytesSent = Serial.write("hello Arduino , I am a beginner in the
Arduino world");
}
Serial.flush()
~ 59 ~
(buffer)
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.write(45); // send a byte with the value 45
int bytesSent = Serial.write("hello Arduino , I am a beginner in the
Arduino world");
Serial.flush();
}
Arduino
~ 60 ~
~ 61 ~
CPU
CPU
~ 62 ~
1
2
3
4
30Kg
30-300Kg
300Kg
I 10-6
II 10-5<<10-6
III 10-3<<10-5
IV 10-2<<10-3
1.
~ 63 ~
2.
3. ()
4.
5.
6.
7. ()
8.
9.
10. e
11.
1.
()
2.
3.
120%
4.
5.
6.
;d
7.
60Kg5g5g
8.
=( e )300g
0.001g0.001g
9.
10g 10g
100kg10g(1001000)10=1000010000
~ 64 ~
10.
6000g
0.5g 05/6000=1/12000 1/12000
11.
12.
13.
14.
CPU
Counting Scale
15.
16.
OFFSET COUNT
~ 65 ~
~ 66 ~
1971 Ralph S.Shoberg
(Shoberg, 1971, Shoberg, 1976, Shoberg, 1978)
4
(Load Cell)
5
~ 67 ~
~ 68 ~
~ 69 ~
Strain gauge
()
resistivity
R=
L
Ac
.....(1)
resistivity
-m
Eq. (1)
dR =
Ac ( Ld + dL) LdAc
.....(2)
Ac
dR d dL dAc
=
+
.....(3)
R
L
Ac
~ 70 ~
Poissons ratio
dAc
dL
= 2 .....(4)
Ac
L
R
L
L
Eq. (5) Eq. (6)
dR d
dL
=
+ (1 + 2 )
..... (6)
R
L
Gage Factor (GF)
d
dR
GF = R = 1 + 2 + .....(7)
dL
dL
L
L
d
Eq. (7) 0 Poisons ratio
0.3 GF = 1 + 2 1.6
dL
L (axial strain)
dL
.....(8)
L
~ 71 ~
dR
= GF .....(9)
R
(strain
Strain gauge
strain gauge, strain gage(
8 )1938 Edward E. Simmons(Simmons, 1942, Simmons,
~ 72 ~
( 8 )
:(a).(Wire)(b).(foil)
()
8
Wheatstone bridge
1833 Samuel Hunter Christie 1843
(Stein, 1990)
~ 73 ~
9
(, et al., 2003)
R1 R2
=
R2 = R
R4 R3
( R 1 = R 3 = R 4 = R ) R2 = R + R
1 (, et al., 2003)
~ 74 ~
R + R
R
E0 =
Vexc
Vexc
R + R + R
R+R
R
R + R
=
Vexc
2 R + R 2 R
2 R 2 + 2 R R 2 R 2 + R R
=
Vexc
(2 R + R )(2 R )
R R
= 2
Vexc
4 R + 2 R R
R R
V
=
2 exc
4R
if 4 R 2 >> 2 R R
1 R
=
Vexc
4 R
1
(, et al., 2003)
10
(, et al., 2003)
R1 = R3 = R R C
R2 = R4 = R + R T
~ 75 ~
(, et al., 2003)
R + R
R R
E0 =
Vexc
Vexc
R + R + R R
R + R + R R
R R + R + R
=
Vexc
2R
R
=
Vexc
R
R
Vexc
E0 =
R
2
(, et al., 2003)
Arduino
( 10 )
24 Analog to Digital Converters (ADC)
~ 76 ~
ADC
~ 77 ~
11 HX711 ADC
~ 78 ~
12 HX711 ADC
HX711 24 A/D
A
B A 128
6420mV 40mV B
64
A/D
HX711
4.8-5.5v
1.6mA
2.9cm * 1.7cm * 0.4cm
~ 79 ~
(STC15F104)
3264 128
A/D
Tx/Rx
10Hz 80Hz
50Hz 60Hz
< 1.7mA, < 1A
2.6 ~ 5.5V
-20 ~ +85
(Load Cell)
A A+ A~ 80 ~
B B+ B-
HX711DIOSCK
22k
J1
HX71180hz/10hz
4.7V5.5V5.5V
4.7V
BB+ B-
HX711
13 HX711
13
~ 81 ~
13 AD
Arduino 14
115200
/do/ck
1 A 128db
~ 82 ~
14 A 128db
HX711
15 HX7118STCSTC15F104
SOP8 15
~ 83 ~
15 HX711
/A/D
HX711 24A/D
MCU
A B
A 128 64
20mV 40mV B 32
~ 84 ~
A/D
64 128
A/D
Tx/Rx
10Hz 80Hz
50Hz 60Hz
< 1.7mA,
< 1A
2.6 ~ 5.5V
~ 85 ~
-20 ~ +85
16 HX711
16 HX711
(, 2013)
17 HX711Pin
SOP-16
17 HX711 SOP-16
(, 2013)
2 HX711
~ 86 ~
3 HX711
2 HX711 SOP-16 ()
Pin #
Name
Function
Description
VSUP
Power
BASE
Analog Output
AVDD
Power
VFB
Analog Input
Ground
Analog Ground
VBG
Analog Output
INA-
Analog Input
INA+
Analog Input
INB-
Analog Input
10
INB+
Analog Input
11
PD_SCK
AGND
clock input
Digital Output
XO
Digital I/O
XI
Digital Input
12
DOUT
13
14
on-chip oscillator
15
RATE
Digital Input
16
DVDD
Power
(, 2013)
~ 87 ~
3 HX711 SOP-16
VSUP
: 2.6 ~ 5.5V
AVDD
BASE
AVDD
: 2.6 ~ 5.5V
VFB
AGND
VBG
INA-
INA+
INB-
10
INB+
11
PD_SCK
Tx/Rx
12
DOUT
Tx/Rx
13
XO
14
XI
0:
15
RATE
0: 10Hz; 1: 80Hz
16
DVDD
: 2.6 ~ 5.5V
(, 2013)
~ 88 ~
4 HX711 ()
Parameter
Full scale
Notes
V(inp)-V(inn)
MIN
TYP
MAX
UNIT
V
0.5(AVDD/GAIN)
differential
input range
Common
mode
AGND+1.2
AVDD-1.3
input
Output data rate
10
80
DVDD
Hz
fclk/1,105,920
RATE = 0
Crystal or external clock,
fclk/138,240
RATE = DVDD
Output data coding
2s complement
RATE = 0
400
RATE = DVDD
50
Gain = 128
0.2
Gain = 64
0.4
Gain = 128RATE = 0
50
90
nV/
GainGain = 128
ppm/
Gain = 128RATE = 0
100
dB
Input noise
Temperature drift
Input common
800000
mode
rejection
~ 89 ~
7FFFFF
HEX
50
mV
nV(rms)
Power
supply
Gain = 128RATE = 0
100
dB
1.25
rejection
Reference bypass
VBG
Crystal or external
11.0592
20
MHz
clock frequency
Power
supply
voltage
Analog
supply
current
(including
regulator)
Digital
supply
current
DVDD
2.6
5.5
AVDDVSUP
2.6
5.5
Normal
1400
Power down
0.3
Normal
100
Power down
0.2
(, 2013)
5 HX711
V(inp)-V(inn)
AGND+0.6 AVDD-0.6
0.5(AVDD/GAIN)
RATE = 0
V
V
10
RATE
Hz
80
= DVDD
RATE
= 0
~ 90 ~
fclk/1,105,920
RATE = DVDD
fclk/138,240
(1)
RATE = 0
800000 7FFFFF(HEX)
400
RATE = DVDD
= 128
50
0.2
= 64
ms
mV
0.8
= 128RATE = 0
50
= 128RATE =
nV(rms)
90
DVDD
7
nV/
= 128
ppm/
= 128RATE = 0
100
dB
= 128RATE = 0
100
dB
VBG
1.25
=
128
V
11.0592 30
MHz
DVDD
2.6 5.5
AVDDVSUP
2.6 5.5
1600
0.3
100
0.2
(, 2013)
~ 91 ~
A
A/D
128 64
20mV 40mV B 32
80mV B
XI HX711
10Hz 80Hz
20pF XIXI XO
11.0592MHz,
10Hz 80Hz
MCU
~ 92 ~
20pF XI
150mV
Tx/Rx
Tx/RxPD_SCK DOUT
DOUT A/D
Tx/RxPD_SCK DOUT
PD_SCK 25 27
24
MSB24 24
2527 A/D
6
6 A/D
PD_SCK
25
128
26
32
27
64
PD_SCK 25 27Tx/Rx
A/D A/D 4
DOUT 4
~ 93 ~
18 HX711
7 HX711
Symbol
Note
T1
0.1
T2
T3
0.2
T4
0.2
s
0.1
50
s
s
(, 2013)
~ 94 ~
19 HX711
(, 2013)
PD_SCK 60sHX711
19
A/D PD_SCK
A 128 A/D
PD_SCK Tx/Rx
A/D 4
DOUT 4
20 HX711
(XI=0)10Hz (RATE=0) 2.7
5.5V) MCU
PNP S8550 R1R2 A/D
A B
~ 95 ~
20
20 HX711
(, 2013)
\
HX711
1. RATE XI PD_SCK
2.
3. A B
4. PNP S8550
MOS
5. A/D
6. 25 27 Tx/Rx
~ 96 ~
HX711 Analog to Digital Converters (ADC)
Arduino
~ 97 ~
~ 98 ~
(Load Cell)
Arduino
13 (Load Cell)
HX711 8 (Load Cell)
HX711
8 HX711
HX711
E+()
+(:)
E-()
GND(:)
A+(/)
A+(:)
()
A-()
A-(:)
()
~ 99 ~
9 HX711 Arduino
HX711
Arduino
Do/Rx
DO/RX
Clock
CK/TX
Vcc
Arduino pin 5V
5V
GND
Arduino sketch
Arduino
HX711 (hx711_1)
#include <HX711.h> // HX711 Arduino library
#define datapin 8
//
#define clockpin 9 //
HX711 hx(clockpin, datapin,128);
// HX711
void setup() {
Serial.begin(9600);
}
void loop()
{
double sum = 0;
//
10
for (int i = 0; i < 10; i++) //
sum += hx.read(); //
Serial.println(sum/10); //
}
21
10
~ 100 ~
21
10 ()
-14175.70
-14365.20
-14380.20
-14514.20
-14388.90
-14452.90
-14481.20
-14498.90
-14593.50
-14456.00
-14555.50
-14387.70
-14504.30
~ 101 ~
()
10000
0
-10000 1
-20000
0()
22 ()
23 100
11
23 100
~ 102 ~
11 ( 100 )
16838.60
16870.40
16894.50
16787.20
16744.50
16901.50
16845.60
16821.20
16844.90
16878.10
16890.00
16803.00
16875.00
(100)
20000
15000
10000
100()
5000
0
1
24 ( 100 )
25 500
12
~ 103 ~
25 500
12 ( 500 )
142037.90
142217.09
142129.40
142273.40
142258.40
142298.59
142302.20
142069.79
142172.90
141995.50
142230.20
142085.79
142271.50
~ 104 ~
(500)
200000
100000
0
500()
26 ( 500 )
10 -14370.82875
12 100 16876.45 500
142028.1371 11
a = -14370.82875
100 c=16876.45
500 b=142028.1371
p=
( ADC - ADC)
3
p=
( ADC - ADC)
~ 105 ~
p=
100
100
= 0.0032002787
( 16876.45 - (-14370.82875))
400 p =
500
400
= 0.0031961215
(142028.1371 - 16876.45)
0.0031977841 0.0031977841
0.0031977841
27
13
Step2
HX711 (hx711_2)
#include <HX711.h> // HX711
Arduino library
#define datapin 8
//
#define clockpin 9 //
HX711 hx(clockpin, datapin,128, 0.0031977841 );
void setup() {
Serial.begin(9600);
}
void loop()
{
~ 106 ~
// HX711
HX711 (hx711_2)
double sum = 0;
//
10
for (int i = 0; i < 10; i++) //
sum += hx.read(); //
Serial.println(sum/10); //
}
27
13 ()
-13296.00
-13239.10
-13107.50
-12982.90
-13061.40
-13083.80
-13271.50
-13161.10
-13157.80
-13309.20
~ 107 ~
-13274.20
-13311.60
-13314.70
()
5000
0
-5000
0()
-10000
-15000
28 ()
29 100
11
~ 108 ~
29 100
14 ( 100 )
18026.40
18005.50
18081.40
17976.60
17976.80
18060.50
17986.70
17967.70
18020.10
18115.80
18246.00
18169.20
18078.40
(100)
20000
15000
10000
100
5000
0
1
30 ( 100 )
31 500
500 15
~ 109 ~
31 500
15 ( 500 )
143485.59
143496.20
143591.29
143614.90
143578.29
143534.70
143440.20
143461.59
143406.90
143367.59
143293.20
143509.20
143402.20
~ 110 ~
(500)
200000
150000
100000
500
50000
0
1
32 ( 500 )
13 -13117.91613
14 100 18148.34241 15
500 143325.8016
a =-13117.91613
100 b=18148.34241
500 c=143325.8016
p=
( ADC - ADC)
100
p=
100
= 0.0031983360
( 18148.34241 - (-13117.91613))
400
p=
400
= 0.0031954635
( 143325.8016 - 18148.34241)
~ 111 ~
500
16
33 34
0.0031977841
0.0031977841
16
ADC ADC
100
31250.76067
31266.25854
0.003199922110
0.003198335991
0.000001586118
400
125148.2052
125177.4592
0.003196210440
0.003195463484
0.000000746956
500
156398.9659
156443.7178
0.003196952085
0.003196037573
0.000000914512
104265.9772
104295.8118
0.003197694878
0.003196612349
0.000001082529
ADC
ADC
40
ADC
20
0
-20
100
400
500
-40
33 ADC
~ 112 ~
ADC
0.003202000000
0.003200000000
0.003198000000
0.003196000000
0.003194000000
0.003192000000
100
400
500
34
0.0031977841
ADC -13117.91613
HX711 (hx711_3)
#include <HX711.h> // HX711
Arduino library
#define datapin 8
//
#define clockpin 9 //
HX711 hx(clockpin, datapin,128,0.0031977841);
void setup() {
hx.set_offset(-13117.91613);
Serial.begin(9600);
}
void loop() {
delay(500);
~ 113 ~
// HX711
HX711 (hx711_3)
double sum0 = 0;
double sum1 = 0;
for (int i = 0; i < 10; i++) {
sum0 += hx.read();
sum1 += hx.bias_read();
}
Serial.print(sum0/10);
Serial.print(" ");
Serial.println(sum1/10);
}
Arduino
17
17
-24961.30 0.31
-25042.10 0.06
-24981.30 0.20
37749.10 200.51
37719.40 200.24
37597.30 199.95
37582.50 199.87
37647.40 200.08
69114.80 299.76
69011.80 300.44
68868.80 300.50
100459.30 399.97
100351.60 400.16
100325.80 400.23
131672.59 500.06
131693.40 500.40
131663.29 500.29
37689.80 199.87
37639.10 200.10
~ 114 ~
22020.40 150.24
22022.10 150.24
EXCEL 18
18 1
0.165714286
(0.165714286) 0.2
18
ADC
-24961.3
0.31
0.31
-25042.1
0.06
0.06
-24981.3
0.2
0.2
37749.1
200.51
200
0.51
37719.4
200.24
200
0.24
37597.3
199.95
200
-0.05
37582.5
199.87
200
-0.13
37647.4
200.08
200
0.08
69114.8
299.76
300
-0.24
10
69011.8
300.44
300
0.44
11
68868.8
300.5
300
0.5
12
100459.3
399.97
400
-0.03
13
100351.6
400.16
400
0.16
14
100325.8
400.23
400
0.23
15
131672.59
500.06
500
0.06
16
131693.4
500.4
500
0.4
17
131663.29
500.29
500
0.29
18
37689.8
199.87
200
-0.13
19
37639.1
200.1
200
0.1
20
22020.4
150.24
150
0.24
21
22022.1
150.24
150
0.24
22
252.5467
252.381
0.165714
~ 115 ~
600
500
400
300
200
100
0
-100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
35
18 35
x
(0.165714286)
0.2
~ 116 ~
~ 117 ~
19
36
0.0031977841 Analog
to Digital Converters (ADC)-13117.91613 Arduino
~ 118 ~
hx.set_offset(-13117.91613)-13117.91613
0
19 0 -61.72
19
ADC
-32433
-61.72
0.013333
-61.7333
-32463.9
-61.81
-0.07667
-32427.6
-61.67
0.063333
-1108.5
38.41
0.1125
-1121.9
38.28
-0.0175
-1181.9
38.17
-0.1275
-1129.9
38.33
0.0325
30153.8
138.27
-0.09
30155.4
138.39
0.03
30175.4
138.44
0.08
30142.5
138.32
-0.04
30154.9
138.38
0.02
92688.9
338.59
0.16
92759.1
338.27
-0.16
92683.8
338.56
0.13
92716.9
338.21
-0.22
92688.6
338.52
0.09
123959.2
438.42
0.12
124046
438.5
0.2
123939.9
438.3
123906.6
438.26
-0.04
123918.5
438.09
-0.21
123937.7
438.35
0.05
100
200
400
500
38.2975
138.36
338.43
438.3
0.005217391
19
~ 119 ~
0.005217391 Analog to Digital Converters (ADC)
0
HX711 Arduino 20
void tare(int t)
20 HX711 Arduino
HX711(byte sck, byte dout, byte amp = 128, double co = 1); // sckdout
128 1
void set_amp(byte amp); // read()
HX711 (hx711_4)
#include <HX711.h> // HX711 Arduino library
~ 120 ~
HX711 (hx711_4)
#define datapin 8
//
#define clockpin 9 //
HX711 hx(clockpin, datapin,128,0.0031977841);
// HX711
void setup() {
hx.set_offset(-13117.91613);
Serial.begin(9600);
hx.tare(50);
// 50
}
void loop() {
delay(500);
double sum0 = 0;
double sum1 = 0;
for (int i = 0; i < 10; i++) {
sum0 += hx.read();
sum1 += hx.bias_read();
}
Serial.print((int)sum0/10); //
Serial.print(" ");
Serial.println((int)sum1/10);
//
}
21 Analog to
Digital Converters (ADC)
21
ADC
-1398
-1373
-1333
-1374
100
-2820
100
100
-2765
100
100
-2829
100
~ 121 ~
100
-2817
100
100
-2827
100
200
2297
200
200
2238
200
200
2295
200
300
819
300
300
789
300
300
777
300
400
-684
400
400
-706
400
400
-758
400
400
-723
400
500
-2198
500
500
-2267
500
500
-2243
500
LCD
Arduino sketcch
( 4)
Hitachi HD44780 LCD controller is one of the most common dot matrix liquid crystal display
(LCD) display controllers available. Hitachi developed the microcontroller specifically to drive
alphanumeric LCD display with a simple interface that could be connected to a general purpose
microcontroller or microprocessor
~ 122 ~
37 LCD 1602
16 22
37 LCD1602
22 LCD1602
Ground (0V)
(0V)
(+5V)
Contrast adjustment;
variable resistor
through
a (0-5V), 1k
LCD
~ 123 ~
I/O
Bit 0 LSB
Bit 1
Bit 2
10
Bit 3
11
Bit 4
12
Bit 5
13
Bit 6
14
15
Bit 7 MSB
( 330 R )
16
(GND)
(Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013)
LCD1602
(Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013) 38
LCD 1602 Arduino 39 LCD 1602
Arduino LCD 1602
LCD 1602 LiquidCrystal Library
Arduino LiquidCrystal Library
http://arduino.cc/en/Reference/LiquidCrystal LCD 1602
LCD 1602
(Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013)
38 LCD 1602
by Fritzing (Interaction_Design_Lab, 2013)
39 LCD 1602
by Fritzing (Interaction_Design_Lab, 2013)
~ 125 ~
/*
LiquidCrystal Library - Hello World
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
~ 126 ~
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
1.
LiquidCrystal lcd ()
2.
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal.begin(16, 2)
1.
lcd ()
2.
LiquidCrystal.begin(16, 2)
lcd 16
LiquidCrystal.setCursor(0, 1)
1.
LiquidCrystal.setCursor(,) 0 , 0
2.
LiquidCrystal.setCursor(0, 1)
16
LiquidCrystal.print()
1.
~ 127 ~
2.
lcd.print("hello, world!");
hello, world!
LiquidCrystal.autoscroll()
1.
lcd
2.
lcd.autoscroll();
lcd.print(thisChar);
16
LiquidCrystal - Text Direction
print()
LiquidCrystal.noAutoscroll()
1.
lcd
2.
lcd.noAutoscroll();
lcd.print(thisChar);
16
print()
16
~ 128 ~
LiquidCrystal.blink()
1.
lcd
2.
lcd.blink();
lcd
LiquidCrystal.noBlink()
1.
lcd
2.
lcd.noBlink ();
lcd
LiquidCrystal.cursor()
1.
lcd
2.
lcd.cursor();
lcd
LiquidCrystal.clear()
1.
lcd
2.
~ 129 ~
lcd.clear();
lcd
LiquidCrystal.home()
1.
lcd
2.
lcd.home();
lcd
Arduino 40 LCD
1602 button LCD
KeyPad LCD
(DFRobot, 2013)
~ 130 ~
Arduino 40 LCD
1602 (buttons) LCD Keypad Shield (DFRobot,
2013) LCD
~ 131 ~
Arduino
D4
D5
D6
D7
RS
Register Selections
Enable
ENABLE SIGNAL
A0
Key buttons ()
5V
Arduino pin 5V
5V
GND
LCD 1602
~ 132 ~
}
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Push the buttons"); // print the message
}
void loop()
{
lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over
lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) {
case btnRIGHT:
{
lcd.print("RIGHT ");
break;
}
case btnLEFT:
{
lcd.print("LEFT ");
break;
}
case btnUP:
{
lcd.print("UP ");
break;
}
case btnDOWN:
{
lcd.print("DOWN ");
break;
}
case btnSELECT:
{
lcd.print("SELECT");
~ 134 ~
break;
}
case btnNONE:
{
lcd.print("NONE ");
break;
}
}
}
42 keypadshield
LCD
Arduino sketcch
( 4)
24
Arduino
D4
D5
D6
D7
RS
Register Selections
Enable
ENABLE SIGNAL
A0
Key buttons ()
5V
Arduino pin 5V
5V
GND
LCD 1602
25 HX711 Arduino
HX711
Arduino
Do/Rx
Do/Rx
Clock
Ck/Tx
Vcc
Arduino pin 5V
5V
GND
(hx711_5)
#define datapin 10
//
#define clockpin 11 //
HX711 hx(clockpin, datapin,128,0.0031977841);
// HX711
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed
reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup() {
hx.set_offset(-13117.91613);
Serial.begin(9600);
hx.tare(50); // 50
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
// lcd.print("Push the buttons"); // print a simple message
}
void loop() {
int key ;
delay(500);
double sum0 = 0;
double sum1 = 0;
~ 137 ~
(hx711_5)
key = checkkey();
if (key == 11)
{
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("tare .........");
hx.tare(50); // 50
delay(1000);
}
for (int i = 0; i < 10; i++) {
sum0 += hx.read();
sum1 += hx.bias_read();
}
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("ADC :"); // display adc value
lcd.print((int)sum0/10); // display adc value
lcd.print(" "); // display adc value
lcd.print(key); // display adc value
lcd.setCursor(0,1); // move to the begining of the second line
lcd.print((int)sum1/10); //
lcd.print(" g "); //
lcd.print(sum1/10); //
lcd.print(" g"); //
Serial.print(sum0/10); //
Serial.print(" ");
Serial.println((int)sum1/10); //
// checkkey();
}
int checkkey()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) {
case btnRIGHT:
{
return 1 ;
break;
~ 138 ~
(hx711_5)
}
case btnLEFT:
{
return 2 ;
break;
}
case btnUP:
{
return 3 ;
break;
}
case btnDOWN:
{
return 4 ;
break;
}
case btnSELECT:
{
return 11 ;
break;
}
case btnNONE:
{
return 0 ;
break;
}
} }
Arduino
43 Keypad Shield
LCD 1602 Select
(Tare)
~ 139 ~
43
(Analog Sensor)
~ 140 ~
~ 141 ~
~ 142 ~
~ 143 ~
(Internal
Clock)
Arduino
Arduino (Tx/Rx),
Arduino http://arduino.cc/en/Reference/SoftwareSerial
Arduoino
Arduino
~ 144 ~
3.
Leonardo
RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
(Uart_test1)
/*
Software serial multple serial test
The circuit: * RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53,
62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15
(SCK), 16 (MOSI).
*/
#include <SoftwareSerial.h>
#define RXPin 5
#define TXPin 6
SoftwareSerial mySerial(RXPin, TXPin); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
~ 145 ~
Arduino (Uart)
(Crowe, et al., 1988, Gulick, et al., 1990, Gulick, et al., 1993, Michael, 1989,
Michael, 1993, Michael, 1995, Michael, 1996, Michael, 1999, Story, et al., 1998,
Takahashi and Ibuka, 1998)(Method)
SoftwareSerial(rxPin, txPin))
SoftwareSerial mySerial =
SoftwareSerial(rxPin,
SoftwareSerial(rxPin, txPin)
SoftwareSerial.begin(speed)
(baud rate) 300, 600, 1200, 2400, 4800, 9600,
14400, 19200, 28800, 31250, 38400, 57600, and 115200 9600 bps(bit per
second)
SoftwareSerial.begin(9600)
9600 bps( 9600 )
SoftwareSerial.available()
(Rx)(Bytes)
//
SoftwareSerial.read() ;
//
endif
,(
~ 146 ~
)
SoftwareSerial.isListening()
//
SoftwareSerial.print(data)
SoftwareSerial.println(data)
Tx
// Hello World
Hello World Tx
SoftwareSerial.read()
(Bytes)
//
SoftwareSerial.read() ;
//
endif
(Bytes)
SoftwareSerial.write(Byte Data)
(Bytes)(Tx)
SoftwareSerial.write(byte) ;
// byte (Tx)
endif
~ 147 ~
(Bytes)(Tx)
SoftwareSerial.peek()
(Rx)(Bytes)
peek()
//
SoftwareSerial.peek() ;
//
endif
(Rx)(Bytes)
peek()
SoftwareSerial.overflow()
true
( false)
if (SoftwareSerial.overflow ())
//
Serial.println("SoftwareSerial overflow!");
//
endif
true
( false)
Com277(
)(USB TTL ( 44))
putty8 (Tatham, 2013) ( Simon
Tatham
).
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
45 45 Arduino
HX711_6( Tx/Rx )
#include <HX711.h> // HX711 Arduino library
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define datapin 10
//
#define clockpin 11 //
#define RXPin 2
// Rx pin
#define TXPin 3
// Tx pin
HX711 hx(clockpin, datapin,128,0.0031977841);
// HX711
HX711_6( Tx/Rx )
{
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for
speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below:
return btnNONE; // when all others fail, return this...
}
void setup() {
hx.set_offset(-13117.91613);
Serial.begin(9600);
mySerial.begin(9600);
hx.tare(50); // 50
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
// lcd.print("Push the buttons"); // print a simple message
}
void loop() {
int key ;
delay(500);
double sum0 = 0;
double sum1 = 0;
key = checkkey();
if (key == 11)
{
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("tare .........");
hx.tare(50); // 50
delay(1000);
}
for (int i = 0; i < 10; i++) {
sum0 += hx.read();
~ 150 ~
HX711_6( Tx/Rx )
sum1 += hx.bias_read();
}
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("ADC :"); // display adc value
lcd.print((int)sum0/10); // display adc value
lcd.print(" "); // display adc value
lcd.print(key); // display adc value
lcd.setCursor(0,1); // move to the begining of the second line
lcd.print((int)sum1/10); //
lcd.print(" g "); //
lcd.print(sum1/10); //
lcd.print(" g"); //
Serial.print(sum0/10); //
Serial.print(" ");
Serial.println((int)sum1/10); //
mySerial.print(sum0/10); //
mySerial.print(" ");
mySerial.println((int)sum1/10);
//
// checkkey();
}
int checkkey()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an
action
{
case btnRIGHT:
{
return 1 ;
break;
}
case btnLEFT:
{
return 2 ;
break;
}
~ 151 ~
HX711_6( Tx/Rx )
case btnUP:
{
return 3 ;
break;
}
case btnDOWN:
{
return 4 ;
break;
}
case btnSELECT:
{
return 11 ;
break;
}
case btnNONE:
{
return 0 ;
break;
}
}
}
~ 152 ~
44 USB TTL
45
45
~ 153 ~
HX711_7 newflag
oldWht
HX711_7( Tx/Rx )
#include <HX711.h> // HX711rduino library
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#define datapin 10
#define clockpin 11
#define RXPin 2
// Rx pin
#define TXPin 3
// Tx pin
//------define key button -----#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
//------define key button -----int lcd_key = 0 ;
int adc_key_in = 0 ;
double sum0 = 0 ;
double sum1 = 0 ;
int newflag = 0 ;
int oldWht = 0 ;
HX711 hx(clockpin, datapin,128,0.0031977841);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
~ 154 ~
HX711_7( Tx/Rx )
SoftwareSerial mySerial(RXPin, TXPin); // RX, TX
void setup() {
// int oldWht;
hx.set_offset(-13117.91613);
Serial.begin(9600);
mySerial.begin(9600);
hx.tare(50);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
// lcd.print("Push the buttons");
// print a simple message
sum0 = 0;
sum1 = 0;
for (int i = 0; i < 10; i++)
{
sum0 += hx.read();
sum1 += hx.bias_read();
}
oldWht = sum1/10 ;
newflag = 0 ;
}
void loop() {
int tmpno = 0 ;
int key ;
key = checkkey();
if (key == 11)
{
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("tare .........");
hx.tare(50);
delay(1000);
}
~ 155 ~
HX711_7( Tx/Rx )
sum0 = 0;
sum1 = 0;
for (int i = 0; i < 10; i++)
{
sum0 += hx.read();
sum1 += hx.bias_read();
}
tmpno = (int)sum1/10 ;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ADC :");
lcd.print((int)sum0/10);
lcd.print(" ");
lcd.print(key);
lcd.setCursor(0,1);
lcd.print((int)sum1/10); \
lcd.print(" g ");
lcd.print(sum1/10);
lcd.print(" g");
Serial.print(sum0/10);
Serial.print(" ");
Serial.println((int)sum1/10);
if( (tmpno> 0) && (tmpno != oldWht) )
{
newflag = 1 ;
}
else
{
newflag = 0 ;
}
if ( newflag == 1)
{
mySerial.print(tmpno) ;
mySerial.println("g") ;
oldWht = tmpno ;
}
~ 156 ~
HX711_7( Tx/Rx )
// checkkey();
delay(500);
}
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for
speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below:
return btnNONE; // when all others fail, return this...
}
int checkkey()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an
action
{
case btnRIGHT:
{
return 1 ;
break;
}
case btnLEFT:
{
return 2 ;
break;
}
case btnUP:
~ 157 ~
HX711_7( Tx/Rx )
{
return 3 ;
break;
}
case btnDOWN:
{
return 4 ;
break;
}
case btnSELECT:
{
return 11 ;
break;
}
case btnNONE:
{
return 0 ;
break;
}
}
}
46
~ 158 ~
46
Arduino
~ 159 ~
(HX711_8) 48
HX711_8()
#include <HX711.h> // HX711rduino library
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "RTClib.h"
~ 162 ~
HX711_8()
#define datapin 10
#define clockpin 11
#define RXPin 2
// Rx pin
#define TXPin 3
// Tx pin
//------define key button -----#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
//------define key button -----int lcd_key = 0 ;
int adc_key_in = 0 ;
double sum0 = 0 ;
double sum1 = 0 ;
int newflag = 0 ;
int oldWht = 0 ;
char datetimestr1[24];
HX711 hx(clockpin, datapin,128,0.0031977841);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
SoftwareSerial mySerial(RXPin, TXPin); // RX, TX
RTC_DS1307 RTC;
//init RTC
void setup() {
// int oldWht;
hx.set_offset(-13117.91613);
Serial.begin(9600);
mySerial.begin(9600);
Wire.begin();
// ds1307
RTC.begin();
// lauch RTC
hx.tare(50);
lcd.begin(16, 2); // start the library
~ 163 ~
HX711_8()
lcd.setCursor(0,0);
sum0 = 0;
sum1 = 0;
oldWht = 0 ;
//
newflag = 0 ;
//
}
void loop() {
int tmpno = 0 ;
int key ;
key = checkkey();
if (key == 11)
{
lcd.clear();
lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over
lcd.print("tare .........");
hx.tare(50);
oldWht = 0 ;
newflag = 0 ;
delay(200);
}
sum0 = 0;
sum1 = 0;
for (int i = 0; i < 10; i++)
{
sum0 += hx.read();
sum1 += hx.bias_read();
}
tmpno = (int)sum1/10 ;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ADC :");
lcd.print((int)sum0/10);
lcd.print(" ");
lcd.print(key);
lcd.setCursor(0,1);
~ 164 ~
HX711_8()
lcd.print((int)sum1/10); \
lcd.print(" g ");
lcd.print(sum1/10);
lcd.print(" g");
Serial.print(getdatetime()) ;
Serial.print(sum0/10);
Serial.print(" ");
Serial.println((int)sum1/10);
if( (tmpno> 0) && (tmpno != oldWht) )
{
newflag = 1 ;
}
else
{
newflag = 0 ;
}
if ( newflag == 1)
{
mySerial.print(getdatetime()) ;
mySerial.print(tmpno) ;
mySerial.println("g") ;
oldWht = tmpno ;
}
// checkkey();
delay(500);
}
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for
speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
~ 165 ~
HX711_8()
if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below:
return btnNONE; // when all others fail, return this...
}
int checkkey()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an
action
{
case btnRIGHT:
{
return 1 ;
break;
}
case btnLEFT:
{
return 2 ;
break;
}
case btnUP:
{
return 3 ;
break;
}
case btnDOWN:
{
return 4 ;
break;
}
case btnSELECT:
{
return 11 ;
break;
}
~ 166 ~
HX711_8()
case btnNONE:
{
return 0 ;
break;
}
}
}
String getdatetime()
{
//
ds1307
~ 167 ~
48
Arduino
Arduino
~ 168 ~
Arduino
~ 169 ~
(Yung-Chung Tsao)
Email:prgbruce@gmail.com
(Chih-Cheng Hsu)(UCLA)
IBM
Email: khsu@mgt.ncu.edu.tw
(Yin-Te Tsai)
Email:yttsai@pu.edu.tw
~ 170 ~
HX711 Arduino
HX711 Arduino librarydea314@gmail.com Google Project
Platform9(dea314@gmail.com, 2013) hx711-Arduino-v0.01
HX711
library
for
Arduino
platform
http://code.google.com/p/hx711-arduino/downloads/list?q=label:Featured :
dea314@gmail.com
hx711.cpp
#include <Arduino.h>
#include <HX711.h>
HX711::HX711(byte sck, byte dout, byte amp, double co) {
SCK = sck;
DOUT = dout;
set_amp(amp);
COEFFICIENT = co;
pinMode(SCK, OUTPUT);
pinMode(DOUT, INPUT);
digitalWrite(SCK, LOW);
read();
}
void HX711::set_amp(byte amp) {
switch (amp) {
case 32: AMP = 2; break;
case 64: AMP = 3; break;
case 128: AMP = 1; break;
9
~ 171 ~
hx711.cpp
}
}
bool HX711::is_ready() {
return digitalRead(DOUT) == LOW;
}
long HX711::read() {
long val = 0;
while (!is_ready());
for (int i = 0; i < 24; i++) {
pulse(SCK);
val <<= 1;
if (digitalRead(DOUT) == HIGH) val++;
}
for (int i = 0; i < AMP; i++) {
pulse(SCK);
}
return val & (1L << 23) ? val | ((-1L) << 24) : val;
}
double HX711::bias_read() {
return (read() - OFFSET) * COEFFICIENT;
}
void HX711::tare(int t) {
double sum = 0;
for (int i = 0; i < t; i++) {
sum += read();
}
set_offset(sum / t);
}
void HX711::set_offset(long offset) {
OFFSET = offset;
}
void HX711::set_co(double co) {
~ 172 ~
hx711.cpp
COEFFICIENT = co;
}
hx711.h
/*
* ---------------------------------------------------------------------------* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice
you
* can do whatever you want with this stuff. If we meet some day, and you
think
* this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
* ---------------------------------------------------------------------------*/
#ifndef HX711_H
#define HX711_H
#define pulse(pin) { digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
#include <Arduino.h>
class HX711
~ 173 ~
hx711.h
{
private:
byte SCK;
byte DOUT;
byte AMP;
long OFFSET;
double COEFFICIENT;
public:
// define sck , dout pin, amplification factor and coefficient
HX711(byte sck, byte dout, byte amp = 128, double co = 1);
// set amplification factor, take effect after one call to read()
void set_amp(byte amp);
// test hx711 is ready or not, will be called in read()
bool is_ready();
// return difference votage, will be blocked if hx711 is not ready
long read();
// return (read() - offset) * coefficient
double bias_read();
// set no-load value to offset, euqla to average of t times read();
void tare(int t = 10);
// set coefficient
void set_co(double co = 1);
// set offset
void set_offset(long offset = 0);
};
#endif
~ 174 ~
LCD 1602
LCD 1602 Adafruit Industries (Adafruit_Industries, 2013)
Basic 16x2 LCD with Arduino library Adafruit Industries
LiquidCrystal.cpp
#include "LiquidCrystal.h"
//
DL = 1; 8-bit interface data
//
N = 0; 1-line display
//
F = 0; 5x8 dot character font
// 3. Display on/off control:
//
D = 0; Display off
//
C = 0; Cursor off
//
B = 0; Blinking off
// 4. Entry mode set:
//
I/D = 1; Increment by 1
//
S = 0; No shift
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set:
LiquidCrystal.cpp
LiquidCrystal.cpp
enable,
{
_rs_pin = rs;
_rw_pin = rw;
_enable_pin = enable;
_data_pins[0] = d0;
_data_pins[1] = d1;
_data_pins[2] = d2;
_data_pins[3] = d3;
_data_pins[4] = d4;
_data_pins[5] = d5;
_data_pins[6] = d6;
~ 177 ~
LiquidCrystal.cpp
_data_pins[7] = d7;
_i2cAddr = 255;
_SPIclock = _SPIdata = _SPIlatch = 255;
pinMode(_rs_pin, OUTPUT);
// we can save 1 pin by not using RW. Indicate by passing 255 instead
of pin#
if (_rw_pin != 255) {
pinMode(_rw_pin, OUTPUT);
pinMode(_enable_pin, OUTPUT);
if (fourbitmode)
else
begin(16, 1);
}
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
// check if i2c
if (_i2cAddr != 255) {
_i2c.begin(_i2cAddr);
_pinMode(_data_pins[i], OUTPUT);
_i2c.pinMode(_rs_pin, OUTPUT);
_i2c.pinMode(_enable_pin, OUTPUT);
} else if (_SPIclock != 255) {
_SPIbuff = 0x80; // backlight
}
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_currline = 0;
// for some 1 line displays you can select a 10 pixel high font
~ 178 ~
LiquidCrystal.cpp
above 2.7V
delayMicroseconds(50000);
_digitalWrite(_rs_pin, LOW);
_digitalWrite(_enable_pin, LOW);
if (_rw_pin != 255) {
_digitalWrite(_rw_pin, LOW);
// figure 24, pg 46
write4bits(0x03);
// second try
write4bits(0x03);
// third go!
write4bits(0x03);
delayMicroseconds(150);
// finally, set to 8-bit interface
write4bits(0x02);
} else {
// this is according to the hitachi HD44780 datasheet
// page 45 figure 23
// Send function set command sequence
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(4500); // wait more than 4.1ms
// second try
~ 179 ~
LiquidCrystal.cpp
command(LCD_FUNCTIONSET | _displayfunction);
delayMicroseconds(150);
// third go
command(LCD_FUNCTIONSET | _displayfunction);
}
// finally, set # lines, font size, etc.
command(LCD_FUNCTIONSET | _displayfunction);
// turn the display on with no cursor or blinking default
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF |
LCD_BLINKOFF;
display();
// clear it off
clear();
// Initialize to default text direction (for romance languages)
_displaymode = LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
/********** high level commands, for the user! */
void LiquidCrystal::clear()
{
delayMicroseconds(2000);
}
void LiquidCrystal::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1;
// we count rows starting w/0
}
~ 180 ~
LiquidCrystal.cpp
}
// Turn the display on/off (quickly)
void LiquidCrystal::noDisplay() {
_displaycontrol &= ~LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turns the underline cursor on/off
void LiquidCrystal::noCursor() {
_displaycontrol &= ~LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// Turn on and off the blinking cursor
void LiquidCrystal::noBlink() {
_displaycontrol &= ~LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
void LiquidCrystal::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
}
// These commands scroll the display without changing the RAM
void LiquidCrystal::scrollDisplayLeft(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE |
LCD_MOVELEFT);
}
void LiquidCrystal::scrollDisplayRight(void) {
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE |
LCD_MOVERIGHT);
~ 181 ~
LiquidCrystal.cpp
}
// This is for text that flows Left to Right
void LiquidCrystal::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This is for text that flows Right to Left
void LiquidCrystal::rightToLeft(void) {
_displaymode &= ~LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'right justify' text from the cursor
void LiquidCrystal::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// This will 'left justify' text from the cursor
void LiquidCrystal::noAutoscroll(void) {
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
}
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
location &= 0x7; // we only have 8 locations 0-7
command(LCD_SETCGRAMADDR | (location << 3));
for (int i=0; i<8; i++) {
write(charmap[i]);
}
}
/*********** mid level commands, for sending data/cmds */
inline void LiquidCrystal::command(uint8_t value) {
send(value, LOW);
}
#if ARDUINO >= 100
inline size_t LiquidCrystal::write(uint8_t value) {
send(value, HIGH);
~ 182 ~
LiquidCrystal.cpp
}
#else
inline void LiquidCrystal::write(uint8_t value) {
send(value, HIGH);
}
#endif
/************ low level data pushing commands **********/
// little wrapper for i/o writes
void LiquidCrystal::_digitalWrite(uint8_t p, uint8_t d) {
if (_i2cAddr != 255) {
// an i2c command
_i2c.digitalWrite(p, d);
} else if (_SPIclock != 255) {
if (d == HIGH)
_SPIbuff |= (1 << p);
else
_SPIbuff &= ~(1 << p);
digitalWrite(_SPIlatch, LOW);
shiftOut(_SPIdata, _SPIclock, MSBFIRST,_SPIbuff);
digitalWrite(_SPIlatch, HIGH);
} else {
// straightup IO
digitalWrite(p, d);
}
}
// Allows to set the backlight, if the LCD backpack is used
void LiquidCrystal::setBacklight(uint8_t status) {
// check if i2c or SPI
if ((_i2cAddr != 255) || (_SPIclock != 255)) {
_digitalWrite(7, status); // backlight is on pin 7
}
}
// little wrapper for i/o directions
void LiquidCrystal::_pinMode(uint8_t p, uint8_t d) {
if (_i2cAddr != 255) {
// an i2c command
return 1;
~ 183 ~
LiquidCrystal.cpp
_i2c.pinMode(p, d);
} else if (_SPIclock != 255) {
// nothing!
} else {
// straightup IO
pinMode(p, d);
}
}
// write either command or data, with automatic 4/8-bit selection
void LiquidCrystal::send(uint8_t value, uint8_t mode) {
_digitalWrite(_rs_pin, mode);
// if there is a RW pin indicated, set it low to Write
if (_rw_pin != 255) {
_digitalWrite(_rw_pin, LOW);
}
if (_displayfunction & LCD_8BITMODE) {
write8bits(value);
} else {
write4bits(value>>4);
write4bits(value);
}
}
void LiquidCrystal::pulseEnable(void) {
_digitalWrite(_enable_pin, LOW);
delayMicroseconds(1);
_digitalWrite(_enable_pin, HIGH);
delayMicroseconds(1);
// enable pulse must be >450ns
_digitalWrite(_enable_pin, LOW);
delayMicroseconds(100);
// commands need > 37us to settle
}
void LiquidCrystal::write4bits(uint8_t value) {
if (_i2cAddr != 255) {
uint8_t out = 0;
out = _i2c.readGPIO();
// speed up for i2c since its sluggish
for (int i = 0; i < 4; i++) {
out &= ~_BV(_data_pins[i]);
~ 184 ~
LiquidCrystal.cpp
LiquidCrystal.h
#ifndef LiquidCrystal_h
#define LiquidCrystal_h
#include <inttypes.h>
#include "Print.h"
#include "Adafruit_MCP23008.h"
~ 185 ~
LiquidCrystal.h
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
~ 186 ~
LiquidCrystal.h
LCD_5x8DOTS);
void clear();
void home();
void noDisplay();
void display();
void noBlink();
void blink();
void noCursor();
void cursor();
void scrollDisplayLeft();
void scrollDisplayRight();
void leftToRight();
void rightToLeft();
void autoscroll();
void noAutoscroll();
LiquidCrystal.h
#endif
void command(uint8_t);
private:
void send(uint8_t, uint8_t);
void write4bits(uint8_t);
void write8bits(uint8_t);
void pulseEnable();
void _digitalWrite(uint8_t, uint8_t);
void _pinMode(uint8_t, uint8_t);
uint8_t _rs_pin; // LOW: command. HIGH: character.
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
uint8_t _enable_pin; // activated by a HIGH pulse.
uint8_t _data_pins[8];
uint8_t _displayfunction;
uint8_t _displaycontrol;
uint8_t _displaymode;
uint8_t _initialized;
uint8_t _numlines,_currline;
uint8_t _SPIclock, _SPIdata, _SPIlatch;
uint8_t _SPIbuff;
uint8_t _i2cAddr;
Adafruit_MCP23008 _i2c;
};
#endif
~ 188 ~
LCD&Keypad Shield
LCD&Keypad Shield Arduino
LCD4Bit_mod.cpp
/*
LCD4Bit
An arduino library for comms with HD44780-compatible LCD, in 4-bit mode
Sources:
- The original "LiquidCrystal" 8-bit library and tutorial
http://www.arduino.cc/en/uploads/Tutorial/LiquidCrystal.zip
http://www.arduino.cc/en/Tutorial/LCDLibrary
Usage:
see the examples folder of this library distribution.
*/
#include "LCD4Bit_mod.h"
extern "C" {
#include <stdio.h> //not needed yet
#include <string.h> //needed for strlen()
#include <inttypes.h>
#include "WConstants.h" //all things wiring / arduino
}
//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02
// --------- PINS ------------------------------------//is the RW pin of the LCD under our control? If we're only ever going to
write to the LCD, we can use one less microcontroller pin, and just tie the
LCD pin to the necessary signal, high or low.
//this stops us sending signals to the RW pin if it isn't being used.
int USING_RW = false;
//RS, RW and Enable can be set to whatever you like
int RS = 8;
~ 189 ~
LCD4Bit_mod.cpp
int RW = 11;
int Enable = 9;
//DB should be an unseparated group of pins - because of lazy coding in
pushNibble()
int DB[] = {4, 5, 6, 7}; //wire these to DB4~7 on LCD.
//-------------------------------------------------------int g_num_lines = 2;
//pulse the Enable pin high (for a microsecond).
//This clocks whatever command or data is in DB4~7 into the LCD controller.
void LCD4Bit_mod::pulseEnablePin(){
digitalWrite(Enable,LOW);
delayMicroseconds(1);
// send a pulse to enable
digitalWrite(Enable,HIGH);
delayMicroseconds(1);
digitalWrite(Enable,LOW);
delay(1); // pause 1 ms. TODO: what delay, if any, is necessary here?
}
//push a nibble of data through the the LCD's DB4~7 pins, clocking with the
Enable pin.
//We don't care what RS and RW are, here.
void LCD4Bit_mod::pushNibble(int value){
int val_nibble= value & 0x0F; //clean the value. (unnecessary)
for (int i=DB[0]; i <= DB[3]; i++) {
digitalWrite(i,val_nibble & 01);
val_nibble >>= 1;
}
pulseEnablePin();
}
//push a byte of data through the LCD's DB4~7 pins, in two steps, clocking
each with the enable pin.
void LCD4Bit_mod::pushByte(int value){
int val_lower = value & 0x0F;
int val_upper = value >> 4;
pushNibble(val_upper);
pushNibble(val_lower);
}
~ 190 ~
LCD4Bit_mod.cpp
//stuff the library user might call--------------------------------//constructor. num_lines must be 1 or 2, currently.
LCD4Bit_mod::LCD4Bit_mod (int num_lines) {
g_num_lines = num_lines;
if (g_num_lines < 1 || g_num_lines > 2)
{
g_num_lines = 1;
}
}
void LCD4Bit_mod::commandWriteNibble(int nibble) {
digitalWrite(RS, LOW);
if (USING_RW) { digitalWrite(RW, LOW); }
pushNibble(nibble);
}
void LCD4Bit_mod::commandWrite(int value) {
digitalWrite(RS, LOW);
if (USING_RW) { digitalWrite(RW, LOW); }
pushByte(value);
//TODO: perhaps better to add a delay after EVERY command, here.
many need a delay, apparently.
}
//print the given character at the current cursor position. overwrites, doesn't
insert.
void LCD4Bit_mod::print(int value) {
//set the RS and RW pins to show we're writing data
digitalWrite(RS, HIGH);
if (USING_RW) { digitalWrite(RW, LOW); }
//let pushByte worry about the intricacies of Enable, nibble order.
pushByte(value);
}
void LCD4Bit_mod::printIn(char msg[]) {
uint8_t i;
for (i=0;i < strlen(msg);i++){
print(msg[i]);
}
}
~ 191 ~
LCD4Bit_mod.cpp
//send the clear screen command to the LCD
void LCD4Bit_mod::clear(){
commandWrite(CMD_CLR);
delay(1);
}
void LCD4Bit_mod::init () {
pinMode(Enable,OUTPUT);
pinMode(RS,OUTPUT);
if (USING_RW) { pinMode(RW,OUTPUT); }
pinMode(DB[0],OUTPUT);
pinMode(DB[1],OUTPUT);
pinMode(DB[2],OUTPUT);
pinMode(DB[3],OUTPUT);
delay(50);
commandWriteNibble(0x03);
delay(5);
commandWriteNibble(0x03);
delayMicroseconds(100);
commandWriteNibble(0x03);
delay(5);
// needed by the LCDs controller
//this being 2 sets up 4-bit mode.
commandWriteNibble(0x02);
commandWriteNibble(0x02);
int num_lines_ptn = g_num_lines - 1 << 3;
int dot_format_ptn = 0x00;
//5x7 dots. 0x04 is 5x10
commandWriteNibble(num_lines_ptn | dot_format_ptn);
delayMicroseconds(60);
commandWrite(0x0C);
delayMicroseconds(60);
//clear display
commandWrite(0x01);
delay(3);
commandWrite(0x06);
delay(1);//TODO: remove unnecessary delays
}
void LCD4Bit_mod::cursorTo(int line_num, int x){
~ 192 ~
LCD4Bit_mod.cpp
//first, put cursor home
commandWrite(CMD_HOME);
if (g_num_lines==1){
line_num = 1;
}
if (line_num == 2){
x += 40;
}
for (int i=0; i<x; i++) {
commandWrite(0x14);
}
}
void LCD4Bit_mod::leftScroll(int num_chars, int delay_time){
for (int i=0; i<num_chars; i++) {
commandWrite(CMD_LEFT);
delay(delay_time);
}
}
LCD4Bit_mod.h
#ifndef LCD4Bit_mod_h
#define LCD4Bit_mod_h
#include <inttypes.h>
class LCD4Bit_mod {
public:
LCD4Bit_mod(int num_lines);
void commandWrite(int value);
void init();
void print(int value);
void printIn(char value[]);
void clear();
void cursorTo(int line_num, int x);
void leftScroll(int chars, int delay_time);
void commandWriteNibble(int nibble);
~ 193 ~
LCD4Bit_mod.h
private:
void pulseEnablePin();
void pushNibble(int nibble);
void pushByte(int value);
};
#endif
~ 194 ~
DS1307
DS1307 Adafruit Industries(Jeelab, 2013) Tiny RTC
I2C library Adafruit Industries
HX711
(, 2013)
~ 202 ~
~ 203 ~
~ 204 ~
~ 205 ~
~ 206 ~
~ 207 ~
~ 208 ~
~ 209 ~
~ 210 ~
LCDKeypad Shield
(DFRobot, 2013)
~ 211 ~
LCM 1602
~ 212 ~
~ 213 ~
~ 214 ~
~ 215 ~
~ 216 ~
~ 217 ~
~ 218 ~
~ 219 ~
~ 220 ~
~ 221 ~
~ 222 ~
~ 223 ~
~ 224 ~
~ 225 ~
~ 226 ~
~ 227 ~
Adafruit Industries LiquidCrystal library for arduino. (2013,
2013.7.3).https://github.com/adafruit/LiquidCrystal
Arduino Arduino official website. (2013, 2013.7.3).http://www.arduino.cc/
Atmel Corporation Atmel Corporation Website. (2013,
2013.6.17).http://www.atmel.com/
Banzi, M., Getting Started with arduino: Make, 2009.
Beckwith, T. G., Marangoni, R. D., and Lienhard, J. H., Mechanical measurements:
Pearson Prentice Hall, 2007.
C, R. A., "Strain responsive apparatus," U.S.A. Patent, 1943.
Coover, H. W., "Stabilized
Alpha-Cyanoacrylate," 1956.
~ 229 ~
Simmons, E. E., "Strain Gauge and Method for Making Same," U.S.A. Patent,
1944.
Stein, P. K., "A brief history of bonded resistance strain gages from conception to
commercialization," Experimental Techniques, vol. 14, pp. 13-19, 1990.
Story, F. H., Harrow, S. E., and Simmons, L. E., "Programming interface for a
universal asynchronous receiver/transmitter," 1998.
Takahashi, Y. and Ibuka, T., "Micro-processor unit having universal asynchronous
receiver/transmitter," 1998.
Simon Tatham PuTTY Download Page. (2013,
2013.7.8).http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Window, A. and Holister, G. S., Strain gauge technology: Applied science
publishers, 1982.
() . (2013). .
2013.http://www.aviaic.com/
, , , and , "," ,
, , ,, 2003.
~ 230 ~