Skip to content

Commit b803527

Browse files
committed
update documentation: LiquidCrystal_I2C new, use mkdoc 1.0.4
1 parent 8434dbb commit b803527

6 files changed

Lines changed: 268 additions & 25 deletions

File tree

docs/api/LiquidCrystal_I2C.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# LiquidCrystal_I2C Library
2+
3+
This library is for character LCDs based on the HD44780 controller connected
4+
via I2C bus using the cheap I2C backpack modules based on the PCF8574(T/A).
5+
6+
It is derived from the
7+
[LiquidCrystal_I2C](https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library)
8+
library as of 09.05.2017 ([commit
9+
e3701fb](https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library/tree/e3701fb3f2398a6d18bfd94a4a7f36e065d57d77)).
10+
by [Frank de Brabander](https://github.com/fdebrabander).
11+
12+
13+
## API
14+
15+
The API is very similar (but, for unknown reasons, not identical) to the API
16+
used by the Arduino LiquidCrystal library for text LCDs with a parallel
17+
interface.
18+
19+
This library is a singleton library, it is not possible to use more than one
20+
instance per sketch.
21+
22+
The API syntax is very similar to the original C++ syntax, thanks to some
23+
[c preprocessor macro magic](../developer/macro).
24+
25+
Apart from the usual name mangeling for polymorph functions (mostly the
26+
different variants of the Print::print method) moving the opening bracket at
27+
the class declarator line and replacing the dots in the method names for
28+
underscores is all it needs.
29+
30+
The original version of the LiquidCystal_I2C library requires the
31+
definition of the LCD size and the desired character size (8 or 10 pixel
32+
height) at the instantiation uses a parameterless begin() method.
33+
34+
This differs slightly from the semantic of the regular Arduino
35+
LiquidCrystal library using the parallel interface. There, the
36+
instantiation defines only the electrical connection (the used pin
37+
numbers) and defines the logical properties (cols, rows, charsize) later
38+
with the begin method.
39+
40+
As an addition to the Arduino version of this library this port
41+
supports both initialization styles.
42+
43+
44+
Arduino syntax |sduino syntax
45+
-------------------- |---------------------
46+
`LiquidCrystal_I2C lcd(i2c_addr,cols,rows,charsize)` |`LiquidCrystal_I2C (lcd,i2c_addr,rows,cols,charsize)`
47+
`LiquidCrystal_I2C lcd(i2c_addr,cols,rows)` |`LiquidCrystal_I2C (lcd,i2c_addr,rows)`
48+
not allowed |`LiquidCrystal_I2C (lcd,i2c_addr)`
49+
`lcd.init(i2c_addr,cols,rows,charsize)` |`lcd_init(i2c_addr,cols,rows,charsize)`
50+
`lcd.begin()` |`lcd_begin()`
51+
not allowed |`lcd_begin_wh(cols,rows)`
52+
not allowed |`lcd_begin_full(cols,rows,charsize)`
53+
`lcd.clear()` |`lcd_clear()`
54+
`lcd.home()` |`lcd_home()`
55+
`lcd.noDisplay()` |`lcd_noDisplay()`
56+
`lcd.display()` |`lcd_display()`
57+
`lcd.noBlink()` |`lcd_noBlink()`
58+
`lcd.blink()` |`lcd_blink()`
59+
`lcd.noCursor()` |`lcd_noCursor()`
60+
`lcd.cursor()` |`lcd_cursor()`
61+
`lcd.scrollDisplayLeft()` |`lcd_scrollDisplayLeft()`
62+
`lcd.scrollDisplayRight()` |`lcd_scrollDisplayRight()`
63+
`lcd.printLeft()` |`lcd_printLeft()`
64+
`lcd.printRight()` |`lcd_printRight()`
65+
`lcd.leftToRight()` |`lcd_leftToRight()`
66+
`lcd.rightToLeft()` |`lcd_rightToLeft()`
67+
`lcd.shiftIncrement()` |`lcd_shiftIncrement()`
68+
`lcd.shiftDecrement()` |`lcd_shiftDecrement()`
69+
`lcd.noBacklight()` |`lcd_noBacklight()`
70+
`lcd.Backlight()` |`lcd_Backlight()`
71+
`result = lcd.getBacklight()` |`result = lcd_getBacklight()`
72+
`lcd.noAutoscroll()` |`lcd_noAutoscroll()`
73+
`lcd.autoscroll()` |`lcd_autoscroll()`
74+
`lcd.createChar(number, data[])` |`lcd_createChar(number, data[])`
75+
`lcd.setCursor(col,row)` |`lcd_setCursor(col,row)`
76+
`result = lcd.write(value)` |`result = lcd_write(value)`
77+
`lcd.command(value)` |`lcd_command(value)`
78+
79+
The library supports the following alias definitions introduced by the
80+
original LiquidCrystal_I2C library. The use of these alias is depreciated
81+
and should be avoided:
82+
83+
Arduino syntax |sduino syntax
84+
-------------------- |---------------------
85+
`lcd_blink_on()` |`lcd_blink_on()`
86+
`lcd_blink_off()` |`lcd_blink_off()`
87+
`lcd_cursor_on()` |`lcd_cursor_on()`
88+
`lcd_cursor_off()` |`lcd_cursor_off()`
89+
`lcd_setBacklight(new_val)` |`lcd_setBacklight(new_val)`
90+
`lcd_load_custom_character(number, data[])`|`lcd_load_custom_character(number, data[])`
91+
`lcd_printstr(string)` |`lcd_printstr(string)`
92+
93+
94+
95+
96+
## Example
97+
98+
Output some Text and count the time since the last reset. Notice the
99+
slightly different position of the opening parenthesis at the "class
100+
constructor" function LiquidCrystal_I2C compared to the C++ instatiation.
101+
102+
```c
103+
#include <Arduino.h>
104+
#include <LiquidCrystal_I2C.h>
105+
106+
// initialize the library with the I2C bus address
107+
// The instance name "lcd" is *within* the brackets
108+
LiquidCrystal_I2C (lcd,0x27,16,2);
109+
110+
void setup() {
111+
lcd_begin();
112+
lcd_print_s("hello, world!");
113+
}
114+
115+
116+
void loop() {
117+
lcd_setCursor(0, 1);
118+
lcd_print_u(millis() / 1000);
119+
}
120+
```
121+
122+
123+
Compare this to the original Arduino C++-Sytax:
124+
125+
```c
126+
#include <LiquidCrystal_I2C.h>
127+
128+
// initialize the library with the I2C bus address
129+
// The instance name "lcd" is *before* the brackets
130+
LiquidCrystal_I2C lcd(0x27,16,2);
131+
132+
void setup() {
133+
lcd.begin();
134+
lcd.print("hello, world!");
135+
}
136+
137+
void loop() {
138+
lcd.setCursor(0, 1);
139+
lcd.print(millis() / 1000);
140+
}
141+
```
142+
143+
144+
As an extention to the original `LiquidCrystal_I2C` libray this Sduino port
145+
supports an initialisation similar to the syntax of the regular
146+
LiquidCrystal library: Defining only the electrical parameters at
147+
instantiation (I2C bus address) and giving the logical parameters (display
148+
size) with the `begin()` method:
149+
150+
```c
151+
#include <Arduino.h>
152+
#include <LiquidCrystal_I2C.h>
153+
154+
// initialize the library with the I2C bus address
155+
// The instance name "lcd" is *within* the brackets
156+
LiquidCrystal_I2C (lcd,0x27);
157+
158+
void setup() {
159+
lcd_begin(16,2);
160+
lcd_print_s("hello, world!");
161+
}
162+
163+
164+
void loop() {
165+
lcd_setCursor(0, 1);
166+
lcd_print_u(millis() / 1000);
167+
}
168+
```
169+
170+
171+
172+
173+
## Possible improvements
174+
175+
This is not a to-do-list, just brainstorming and a collection of random
176+
thoughts.
177+
178+
179+
180+
## Further reading
181+
182+
[Detailed look at the PCF8574 I2C port
183+
expander](https://alselectro.wordpress.com/2016/05/12/serial-lcd-i2c-module-pcf8574/)
184+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Ubuntu, Mint, Elementary etc.):
100100
sudo apt-get install make libusb-1.0-0
101101
```
102102

103-
Now use the Board Mangager to remove the auto-installed Sduino package and
103+
Now use the Board Manager to remove the auto-installed Sduino package and
104104
you are ready.
105105

106106

@@ -148,7 +148,7 @@ Expected folder structure:
148148
+ sdcc can be a link to a full sdcc install
149149
```
150150

151-
>Don't despair of the stock Windows terminal window. Installing e.g.
151+
Don't despair of the stock Windows terminal window. Installing e.g.
152152
[console2](https://sourceforge.net/projects/console/) will make your life on
153153
the command line so much more enjoyable.
154154

docs/hardware/stm8blue.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Generic STM8S103 breakout board
22

33
These simple breakout boards are available on aliexpress for well under one
4-
Dollar (I got mine for 67 cent each, including shipping from China). They
5-
are my original development platform.
4+
Dollar (I got mine for 67 cent each, including shipping from China). These
5+
boards are my main development platform.
66

77
![Image of the STM8S103 board](stm8board-pinout.jpg)
88

@@ -14,10 +14,11 @@ internal oscillator, 8kB flash, 1kB RAM, and 640 byte EEPROM. The CPU
1414
includes a UART, SPI, I2C, PWM, 10 bit ADC, 3 timer, and up to 14 I/O pins -
1515
quite similar to an Atmel ATmega8.
1616

17-
One (red) LED is connected to GPIO PB5 (CPU pin 11). The push button is for
18-
reset. The CPU runs on 3.3V, a linear regulator is integrated on the
19-
board. The micro USB connector is only for (5V) power supply, the data lines
20-
are not connected.
17+
One (red) LED is connected to GPIO PB5 (CPU pin 11). Please keep in mind
18+
that this is one of the I2C signals and **using the LED blocks the I2C
19+
bus**. The push button is for reset. The CPU runs on 3.3V, a linear
20+
regulator is integrated on the board. The micro USB connector is only for
21+
(5V) power supply, the data lines are not connected.
2122

2223
All CPU pins are easily accessible on (optional) pin headers (pitch 2.54mm,
2324
perfect for breadboards).
@@ -41,7 +42,7 @@ housing. The one in the metal housing uses a different pinout.
4142
Connection to the flashtool:
4243

4344
Signal name |P3 on CPU board |Green flash tool|Metal flash tool
44-
------ |-----: |-----: |-----:
45+
------ |:-----: |:-----: |:-----:
4546
3V3 |1 |2 | 7
4647
SWIM |2 |5 | 5
4748
GND |3 |7 | 3
@@ -67,13 +68,6 @@ this mapping:
6768

6869
![STM8S103 breakout board pin mapping](stm8blue.png)
6970

70-
The pins D3/D4 (SDA/SCL, PB5/PB4) are different from the others as they are
71-
true open drain pins. That means, they only can drive the output low or
72-
open. To drive it high, they require the of an external pull-up resistor.
73-
This is the reason why the LED on this breakout is connected between +3.3V
74-
and the pins and not between the pin GND as usual. This way it is possible
75-
to drive the LED by writing a zero to the output register.
76-
7771

7872

7973
sduino pin | STM8S103 CPU port pin
@@ -83,19 +77,24 @@ sduino pin | STM8S103 CPU port pin
8377
5-9 | PC3-PC7
8478
10-15 | PD1-PD6
8579

86-
serial: 14,15
87-
SPI: 2,7,8,9
88-
I2C: 3,4 (true open drain. can't drive a high signal without an external
89-
pull-up resistor)
90-
Analog: 6,11,12,14,15
91-
PWM: 2,5,6,12 plus either only 13 or 7-9 but not 13 (via alternate mapping)
80+
- serial: 14,15
81+
- SPI: 2,7,8,9
82+
- I2C: 3,4 (true open drain. can't drive a high signal without an external
83+
pull-up resistor)
84+
- Analog: 6,11,12,14,15
85+
- PWM: 2,5,6,12 plus either only 13 or 7-9 but not 13 (via alternate mapping)
86+
87+
pros of this approach:
9288

9389
+ Easy and logical for use on a breadboard
9490
+ Very clear and logical port pin ordering
95-
- Analog pins are still scattered around
9691
+ TX and RX would be the rarely used analog pin numbers A3/A4 at
9792
the end of the analog pin number list
9893
+ At least the analog pins are in data sheet order
94+
95+
cons of this approach:
96+
97+
- Analog pins are still scattered around
9998
- All functions use totally different pin numbers than Arduino
10099

101100
I am still not really happy with this mapping. Instead of simplifing things
@@ -126,3 +125,16 @@ paratheses):
126125
|19 |PD2 |Ain3/[T2-3] |11 |Analog A1, (~~)
127126
|20 |PD3 |Ain4/T2-2 |12 |PWM, Analog A2
128127

128+
129+
## Special pins
130+
131+
The pins D3/D4 (SDA/SCL, PB5/PB4) are different from the others as they are
132+
true open drain pins. That means, they only can drive the output low or
133+
open. To drive it high, they require an external pull-up resistor.
134+
This is the reason why the LED on this breakout board is connected between +3.3V
135+
and the pins and not between the pin GND as usual. This way it is possible
136+
to drive the LED by writing a zero to the output register.
137+
138+
139+
D5/D6 (PA1/PA2, OscIn/OscOut) are weaker than the other pins. Try avoiding
140+
these pins for LEDs and other higher current applications.

docs/hardware/w1209-thermostat.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# W1209 Thermostat module
2+
3+
Insanly cheap module with a relay, 3 digit display and a sensor connector.
4+
All of that for $1.60 including shipping!
5+
6+
STM8S000F3P6 microcontroller, 8 KB Flash, 1 KB RAM, 128 bytes EEPROM
7+
8+
- 12V supply voltage
9+
- One relay with indikator LED, max. 5A DC or 15A AC
10+
- three buttons
11+
- three digit 7-segment-display, multiplexed
12+
- external NTC temperture sensor, 10k
13+
14+
But please be aware that the PCB layouts violates all common safety rules on
15+
the high voltage side. No sufficient creeping distance, the PCB traces are
16+
way too small to actually carry 15A and the screw terminals are not up to
17+
that task either.
18+
19+
20+
![connecting the board](https://github.com/mister-grumbler/w1209-firmware/raw/master/docs/st-link_conn_w1209.jpg)
21+
22+
23+
## SWIM connector
24+
25+
Pinout of SWIM connector
26+
27+
Pin | Signal
28+
---: | ------
29+
1 | Vcc (5V)
30+
2 | SWIM
31+
3 | NRST
32+
4 | GND
33+
34+
35+
## Schematic
36+
37+
![Schematic of W1209](https://github.com/mister-grumbler/w1209-firmware/raw/master/docs/thermostat-w1209.jpg)
38+
39+
40+
## Further reading
41+
42+
[Functionally identical firmware, GPL2'ed](https://github.com/mister-grumbler/w1209-firmware)

docs/usage/limitations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ around that is painfully slow.
6060
It would be great if somebody would replace the painfully slow parameter
6161
checking part of the makefile (that causes the majority of forking) by a
6262
single shell script that gets called by the makefile and delivers the
63-
results in no time. Or use [cmake](www.cmake.org). Or integrate it somehow
63+
results in no time. Or use [cmake](https://cmake.org). Or integrate it somehow
6464
into the STVD IDE (This [STVD-SDCC integration
6565
suite](https://github.com/shkolnick-kun/stvd-sdcc) might be useful). Or
6666
whatever.

mkdocs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ site_name: Sduino
22
site_description: Programming the STM8S the Arduino way
33
site_author: Michael Mayer
44
repo_url: 'https://github.com/tenbaht/sduino'
5-
pages:
5+
# using mkdocs 1.0.4 now
6+
nav:
67
- User Guide:
78
- Introduction: 'index.md'
89
- Automatic Installation: 'usage/board-manager-install.md'
@@ -19,6 +20,7 @@ pages:
1920
- SPI: api/SPI.md
2021
- I2C: api/I2C.md
2122
- LiquidCrystal character LCD library: api/LiquidCrystal.md
23+
- LiquidCrystal_I2C character LCD connected via I2C backpack boards: api/LiquidCrystal_I2C.md
2224
- PCD8544 libray for Nokia 5110-like graphical LCDs: api/PCD8544.md
2325
- Mini_SSD1306 library for monochrome OLED-displays: api/Mini_SSD1306.md
2426
- Stepper library: api/Stepper.md
@@ -29,8 +31,11 @@ pages:
2931
- 'Generic STM8S103 breakout board (stm8blue)': hardware/stm8blue.md
3032
- 'ESP14: Wifi board, STM8S003': hardware/esp14.md
3133
- 'STM8S105Discovery: Evaluation board made my ST': hardware/stm8sdiscovery.md
34+
- W1209 thermostat board: 'hardware/w1209-thermostat.md'
3235
- Developer Guide:
3336
- IDE integration: 'developer/ide-integration.md'
37+
- Compiling the tools: 'developer/compiling-the-tools.md'
38+
- Update an automatic installation to a manual installtion: 'developer/update-to-manual.md'
3439
- C preprocessor macro magic: 'developer/macro.md'
3540
- Ways to define a pin mapping: 'developer/pin_mapping.md'
3641
- Using the SDCC compiler: 'developer/sdcc.md'

0 commit comments

Comments
 (0)