Skip to content

Commit c609439

Browse files
author
JoelEB
committed
Initial Commit
0 parents  commit c609439

7 files changed

+969
-0
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 SparkFun Electronics
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## SparkFun SparkFun's Serial Graphic LCD Backpack Particle Library
2+
3+
Firmware library for SparkFun's Serial Graphic LCD Backpack.
4+
5+
About
6+
-------------------
7+
8+
This is a firmware library for [SparkFun's Serial Graphic LCD Backpack](https://www.sparkfun.com/products/9352).
9+
10+
[![SparkFun's Serial Graphic LCD Backpack](https://cdn.sparkfun.com//assets/parts/2/9/2/2/09352-01.jpg)](https://www.sparkfun.com/products/9352).
11+
12+
This is the serial backpack for graphic LCDs. The SparkFun Graphic LCD Serial Backpack interfaces to either our 160x128 pixel “Huge” Graphic LCD, or the smaller 128x64 pixel display, and provides a simple serial interface to a full range of controls.
13+
14+
This backpack will allow you to write text, draw lines, circles and boxes, set or reset individual pixels, and erase specific blocks of the display. The backlight and baud rate can also be controlled via serial communication. There’s also a reverse mode that allows the screen to operate blue on white instead of white on blue. Additionally, all source code for the ATMega168 processor is compiled using the free WinAVR compiler and is free for downloading.
15+
16+
Repository Contents
17+
-------------------
18+
19+
* **/doc** - Additional documentation for the user. These files are ignored by the IDE.
20+
* **/firmware** - Source files for the library (.cpp, .h).
21+
* **/firmware/examples** - Example sketches for the library (.cpp). Run these from the Particle IDE.
22+
* **spark.json** - General library properties for the Particel library manager.
23+
24+
Example Usage
25+
-------------------
26+
27+
Include the Serial Graphic LCD library:
28+
29+
#include "SparkFunMPL3115A2.h" // Include the SparkFun MPL3115A2 library
30+
31+
Recommended Components
32+
-------------------
33+
34+
* [Particle Photon](https://www.sparkfun.com/products/13345)
35+
* [SparkFun Serial Graphic LCD 160x128](https://www.sparkfun.com/products/8884)
36+
* [SparkFun Serial Graphic LCD 128x64](https://www.sparkfun.com/products/9351)
37+
38+
License Information
39+
-------------------
40+
41+
This product is _**open source**_!
42+
43+
Please review the LICENSE.md file for license information.
44+
45+
If you have any questions or concerns on licensing, please contact [email protected].
46+
47+
Distributed as-is; no warranty is given.
48+
49+
- Your friends at SparkFun.

doc/DS-G160128STBWW.pdf

976 KB
Binary file not shown.
+279
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
/**********************************************
2+
Graphic Serial LCD Libary Main File
3+
Joel Bartlett
4+
SparkFun Electronics
5+
9-25-13
6+
7+
Updated for the Particle IDE on 7-2-15
8+
**********************************************/
9+
#include "SparkFun_Serial_Graphic_LCD.h"
10+
11+
LCD::LCD()
12+
{
13+
serial1.begin(115200);
14+
15+
}
16+
//-------------------------------------------------------------------------------------------
17+
void LCD::printStr(char Str[78])//26 characters is the length of one line on the LCD
18+
{
19+
serial1.print(Str);
20+
//if you need to print longer strings, change the size of this array here and in the .h file
21+
}
22+
//-------------------------------------------------------------------------------------------
23+
void LCD::printNum(int num)//can't convert ints to strings so this is just for printing ints
24+
{
25+
serial1.print(num);
26+
}
27+
//-------------------------------------------------------------------------------------------
28+
void LCD::nextLine()//prints new line
29+
{
30+
serial1.println();
31+
}
32+
//-------------------------------------------------------------------------------------------
33+
void LCD::clearScreen()
34+
{
35+
//clears the screen, you will use this a lot!
36+
serial1.write(0x7C);
37+
serial1.write((byte)0); //CTRL @
38+
//can't send LCD.write(0) or LCD.write(0x00) because it's interprestted as a NULL
39+
}
40+
//-------------------------------------------------------------------------------------------
41+
void LCD::toggleReverseMode()
42+
{
43+
//Everything that was black is now white and vise versa
44+
serial1.write(0x7C);
45+
serial1.write(0x12); //CTRL r
46+
}
47+
//-------------------------------------------------------------------------------------------
48+
void LCD::toggleSplash()
49+
{
50+
//turns the splash screen on and off, the 1 second delay at startup stays either way.
51+
serial1.write(0x7C);
52+
serial1.write(0x13); //CTRL s
53+
}
54+
//-------------------------------------------------------------------------------------------
55+
void LCD::setBacklight(byte duty)
56+
{
57+
//changes the back light intensity, range is 0-100.
58+
serial1.write(0x7C);
59+
serial1.write(0x02); //CTRL b
60+
serial1.write(duty); //send a value of 0 - 100
61+
}
62+
//-------------------------------------------------------------------------------------------
63+
void LCD::setBaud(byte baud)
64+
{
65+
//changes the baud rate.
66+
serial1.write(0x7C);
67+
serial1.write(0x07); //CTRL g
68+
serial1.write(baud); //send a value of 49 - 54
69+
delay(100);
70+
71+
/*
72+
“1” = 4800bps - 0x31 = 49
73+
“2” = 9600bps - 0x32 = 50
74+
“3” = 19,200bps - 0x33 = 51
75+
“4” = 38,400bps - 0x34 = 52
76+
“5” = 57,600bps - 0x35 = 53
77+
“6” = 115,200bps - 0x36 = 54
78+
*/
79+
80+
//these statements change the Serial 1 baud rate to match the baud rate of the LCD.
81+
if(baud == 49)
82+
{
83+
serial1.end();
84+
serial1.begin(4800);
85+
}
86+
if(baud == 50)
87+
{
88+
serial1.end();
89+
serial1.begin(9600);
90+
}
91+
if(baud == 51)
92+
{
93+
serial1.end();
94+
serial1.begin(19200);
95+
}
96+
if(baud == 52)
97+
{
98+
serial1.end();
99+
serial1.begin(38400);
100+
}
101+
if(baud == 53)
102+
{
103+
serial1.end();
104+
serial1.begin(57600);
105+
}
106+
if(baud == 54)
107+
{
108+
serial1.end();
109+
serial1.begin(115200);
110+
}
111+
}
112+
//-------------------------------------------------------------------------------------------
113+
void LCD::restoreDefaultBaud()
114+
{
115+
//This function is used to restore the default baud rate in case you change it
116+
//and forget to which rate it was changed.
117+
118+
119+
serial1.end();//end the transmission at whatever the current baud rate is
120+
121+
//cycle through every other possible buad rate and attemp to change the rate back to 115200
122+
serial1.begin(4800);
123+
serial1.write(0x7C);
124+
serial1.write(0x07);
125+
serial1.write(54);//set back to 115200
126+
serial1.end();
127+
128+
serial1.begin(9600);
129+
serial1.write(0x7C);
130+
serial1.write(0x07);
131+
serial1.write(54);//set back to 115200
132+
serial1.end();
133+
134+
serial1.begin(19200);
135+
serial1.write(0x7C);
136+
serial1.write(0x07);
137+
serial1.write(54);//set back to 115200
138+
serial1.end();
139+
140+
serial1.begin(38400);
141+
serial1.write(0x7C);
142+
serial1.write(0x07);
143+
serial1.write(54);//set back to 115200
144+
serial1.end();
145+
146+
serial1.begin(57600);
147+
serial1.write(0x7C);
148+
serial1.write(0x07);
149+
serial1.write(54);//set back to 115200
150+
serial1.end();
151+
152+
serial1.begin(115200);
153+
delay(10);
154+
serial1.write(0x7C);
155+
serial1.write((byte)0); //clearScreen
156+
serial1.print("Baud restored to 115200!");
157+
delay(5000);
158+
159+
}
160+
//-------------------------------------------------------------------------------------------
161+
void LCD::demo()
162+
{
163+
//Demonstartes all the capabilities of the LCD
164+
serial1.write(0x7C);
165+
serial1.write(0x04);//CTRL d
166+
}
167+
//-------------------------------------------------------------------------------------------
168+
void LCD::setX(byte posX) //0-127 or 0-159 pixels
169+
{
170+
//Set the X position
171+
serial1.write(0x7C);
172+
serial1.write(0x18);//CTRL x
173+
serial1.write(posX);
174+
175+
//characters are 8 pixels tall x 6 pixels wide
176+
//The top left corner of a char is where the x/y value will start its print
177+
//For example, if you print a char at position 1,1, the bottom right of your char will be at position 7,9.
178+
//Therefore, to print a character in the very bottom right corner, you would need to print at the coordinates
179+
//x = 154 , y = 120. You should never exceed these values.
180+
181+
182+
// Here we have an example using an upper case 'B'. The star is where the character starts, given a set
183+
//of x,y coordinates. # represents the blocks that make up the character, and _ represnets the remaining
184+
//unused bits in the char space.
185+
// *###__
186+
// # #_
187+
// # #_
188+
// ####__
189+
// # #_
190+
// # #_
191+
// ####__
192+
// ______
193+
}
194+
//-------------------------------------------------------------------------------------------
195+
void LCD::setY(byte posY)//0-63 or 0-127 pixels
196+
{
197+
//Set the y position
198+
serial1.write(0x7C);
199+
serial1.write(0x19);//CTRL y
200+
serial1.write(posY);
201+
202+
}
203+
//-------------------------------------------------------------------------------------------
204+
void LCD::setHome()
205+
{
206+
serial1.write(0x7C);
207+
serial1.write(0x18);
208+
serial1.write((byte)0);//set x back to 0
209+
210+
serial1.write(0x7C);
211+
serial1.write(0x19);
212+
serial1.write((byte)0);//set y back to 0
213+
}
214+
//-------------------------------------------------------------------------------------------
215+
void LCD::setPixel(byte x, byte y, byte set)
216+
{
217+
serial1.write(0x7C);
218+
serial1.write(0x10);//CTRL p
219+
serial1.write(x);
220+
serial1.write(y);
221+
serial1.write(0x01);
222+
delay(10);
223+
}
224+
//-------------------------------------------------------------------------------------------
225+
void LCD::drawLine(byte x1, byte y1, byte x2, byte y2, byte set)
226+
{
227+
//draws a line from two given points. You can set and reset just as the pixel function.
228+
serial1.write(0x7C);
229+
serial1.write(0x0C);//CTRL l
230+
serial1.write(x1);
231+
serial1.write(y1);
232+
serial1.write(x2);
233+
serial1.write(y2);
234+
serial1.write(0x01);
235+
delay(10);
236+
237+
}
238+
//-------------------------------------------------------------------------------------------
239+
void LCD::drawBox(byte x1, byte y1, byte x2, byte y2, byte set)
240+
{
241+
//draws a box from two given points. You can set and reset just as the pixel function.
242+
serial1.write(0x7C);
243+
serial1.write(0x0F);//CTRL o
244+
serial1.write(x1);
245+
serial1.write(y1);
246+
serial1.write(x2);
247+
serial1.write(y2);
248+
serial1.write(0x01);
249+
delay(10);
250+
251+
}
252+
//-------------------------------------------------------------------------------------------
253+
void LCD::drawCircle(byte x, byte y, byte rad, byte set)
254+
{
255+
//draws a circle from a point x,y with a radius of rad.
256+
//Circles can be drawn off-grid, but only those pixels that fall within the
257+
//display boundaries will be written.
258+
serial1.write(0x7C);
259+
serial1.write(0x03);//CTRL c
260+
serial1.write(x);
261+
serial1.write(y);
262+
serial1.write(rad);
263+
serial1.write(0x01);
264+
delay(10);
265+
266+
}
267+
//-------------------------------------------------------------------------------------------
268+
void LCD::eraseBlock(byte x1, byte y1, byte x2, byte y2)
269+
{
270+
//This is just like the draw box command, except the contents of the box are erased to the background color
271+
serial1.write(0x7C);
272+
serial1.write(0x05);//CTRL e
273+
serial1.write(x1);
274+
serial1.write(y1);
275+
serial1.write(x2);
276+
serial1.write(y2);
277+
delay(10);
278+
279+
}

0 commit comments

Comments
 (0)