Quickly: KS0108B Graphic LCD 128×64 + Arduino

Wednesday, October 12 th , 2011

This is an incredibly quick post, and it is actually here simply because this thing was a pain to figure out how to hook it up. But, I wasn’t able to do anything with it more than the Arduino library was able to do out of the box.

So, if you have this screen sold from SparkFun, and you wanted to hook it up to your Arduino, here is how you do that.

Hooking it up

LCD screens of this type are more difficult to work with than ones specifically designed for text. With these you have individual pixel control, so you can draw completely custom graphics with it. But it also means you have to keep track of a lot of pixels, hence all the extra wires. Making matters worse, many of these screens actually require a negative voltage on the dimmer pot to get an image from it. But luckily this particular one includes all the circuitry needed.

Note: this is hookup for the non-mega Arduino. The Arduino Megas actually connect differently to this screen. Just make sure to connect all the wires to the Arduino as seen on the right. You can click on the image to get a closer look.

To drive this graphic display you need a library, and for that, Arduino has you covered: http://www.arduino.cc/playground/Code/GLCDks0108

I know this is a lame excuse for an article. But like I said, it is just here incase you need to know how to hook it up.

High Sensitivity Light Sensor TSL230R + Arduino

Friday, September 9 th , 2011

A while back we covered the TEMT6000, a great little analog sensor for getting ambient light readings when you need something a bit more sensitive than a simple Photoresistor. Well in the spirit of documenting everything we can get our hands on, this week we will be taking the sensitivity to the next level with the TSL230R Light Intensity Sensor.

I actually bought this a long time ago simply because it looked awesome. I mean really… How often do you see a clear chip? That was enough, I had to have it. Well, aside from looking downright awesome, it is also an incredibly sensitive digital light sensor. This awesome guy is sensitive enough to be used for photography light metering, or be able to tell when someone walks by a lamp on the other side of the room. Also, to top it all off, it actually has 3 sensitivity settings, so if you are in a low-light situation, it has you covered!

Hooking it up

So the TSL230R is actually pretty simple, it really only has power, and signal out. But it has a bunch of extra pins so you can change sensitivity and output type if you want. We don’t care about changing the output format, but I did want to keep the “sensitivity select” open for you incase you need it.

So just connect it up to your Arduino as shown in the image. Make sure to take note of either the larger pin in the bottom left (pin 4) or the circle on the top left (pin 1) to make sure you have it facing the right way.

Code

Before we get to far! If you are looking for a photo-ready reading from this sensor, in ISO, ASA, Lux or other, you are in the wrong place. You want this article here: Arduino and the Taos TSL230R Light Sensor: Getting Started.

If you want to be able to check for changes in light, and have some simpler code to tame this beast, keep reading.

So what the TSL230R does, is it sends out a digital Square Wave (simple up and down) signal that gets longer with less light, and shorter with more light. So we need to look at how long the wave is so we can figure out the brightness. We will actually be taking a few samples and averaging them so the signal will be more accurate and smoother. If you are looking at using a threshold to trigger something, you may want to up the number of samples it takes so it is even smoother and you don’t get false positives. (but this will slow down how long it takes to read)

This code simply checks the output of the TSL230R, and prints to the Arduino’s software serial terminal. With higher readings meaning brighter. You can change the sensitivity of the TSL230R as well. In the sketch, under setupTSL230, you can set TSL230_s0, and TSL230_s1 HIGH or LOW to make the sensor more or less sensitive to light. Great for low-light, or ultra-bright situations.

// Reports the frequency from the TSL230, higher number means brighter
// Part: http://www.sparkfun.com/products/8940
// Article:  http://bildr.org/2011/08/tsl230r-arduino/ 

int TSL230_Pin = 4; //TSL230 output
int TSL230_s0 = 3; //TSL230 sensitivity setting 1
int TSL230_s1 = 2; //TSL230 sensitivity setting 2

int TSL230_samples = 6; //higher = slower but more stable and accurate

void setup(){
  Serial.begin(9600);
  setupTSL230();
}

void loop(){

  float lightLevel = readTSL230(TSL230_samples);
  Serial.println(lightLevel);

}

void setupTSL230(){
  pinMode(TSL230_s0, OUTPUT);
  pinMode(TSL230_s1, OUTPUT); 

  //configure sensitivity - Can set to
  //S1 LOW  | S0 HIGH: low
  //S1 HIGH | S0 LOW:  med
  //S1 HIGH | S0 HIGH: high

  digitalWrite(TSL230_s1, LOW);
  digitalWrite(TSL230_s0, HIGH);
}

float readTSL230(int samples){
//sample light, return reading in frequency
//higher number means brighter

  float start = micros();
  int readings = 0;

  while(readings < samples){
   pulseIn(TSL230_Pin, HIGH);
   readings ++;
  }

  float length = micros() - start;
  float freq = (1000000 / (length / samples)) * 10;

  return freq;
}
Unless otherwise stated, this code is released under the MIT License – Please use, change and share it.

Displaying on Paper – Thermal Printer + Arduino

Tuesday, August 30 th , 2011

The following code and library are compatible with arduino software 1.0+ ONLY. You can download the newest version of the arduino software here.

Outputting data can be extremely useful, and typically when we look at doing this, it is either to the Arduino’s serial terminal, or to some sort of display. But what about making physical copies of the data? So a few months back, SparkFun started selling a thermal printer that you could connect to a microcontroller (or via adafruit ). That same day my brain filled with crazy thing you could do with it, like a giant fortune cookie that could print your fortune on the fly.

Anyways… If you dont know about thermal printers, they are most often the printers your store’s receipts are printed on. The reason for this is that they dont use ink, or use a cartridge of any sort. The paper it prints on turns black when heated. So this printer simply applies heat where another printer would apply ink. Eventually the printers head will wear out, but this after several miles of printing. Yes, miles – about 30 of them. So given that the rolls of paper are 34ft long, you can print about 4,600 rolls before the print head dies, meaning for most of us, you will never see that happen.

Hooking it up

So this printer can be powered off of 5V, but NOT the 5v pin on your arduino, and no via USB. It uses very little power when it is is just sitting by, but uses around a full amp when it is printing! And because the most USB can handle is half of that, we need an external power supply. Something between 5 and 9V, and a minimum of 1400ma output (larger is fine). I found that powering the printer with 9v, it printed much faster, and slightly darker than 5v, and if you have it available, I recommend using 9v.

There are two ways of connecting the power supply as shown in the illustrations. You can either power your arduino and the printer separately, or you can power the arduino, and power the printer off of the arduino.

To do the latter, the printer’s power wire (red) needs to connect to the VIN pin on the arduino, not the 5v pin. The reason is that the 5v pin goes through a regulator and is not meant to supply this kind of power, but the VIN pin is directly connected to the power input on the arduino. So it can supply much more.

Now just connect the rest of the wires as shown.

Code

The printer needs a serial connection to the arduino. And normally that would mean we would connect to digital pins 0,1 but, if we did this, anything you printed to the serial terminal for debugging or otherwise the printer would see and possibly print out. We don’t want that, so we will be using a libraty so that you can keep those pins free.

This printer has a huge amount of features. 2 different barcode, text output, size settings etc, and each one needs a new configuration to get it working. So we created a library for this so that you could keep your code clean, and simple.

To make this code work, before you load the code, or even open the Arduino program, we need to place the “Thermal” folder into your Arduino Library. If you don’t know where that is by default, Look to the right.

If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.

Default Library Folder Location

On your Mac:: In (home directory)/Documents/Arduino/libraries
On your PC:: My Documents -> Arduino -> libraries
On your Linux box:: (home directory)/sketchbook/libraries

darkness And Speed Calibration

If you want to get a little more speed, or darkness out of the printer, you can change some settings in the thermal.cpp file of the Thermal library.

heatTime = 120; //80 is default from page 23 of datasheet. Controls speed of printing and darkness
heatInterval = 50; //2 is default from page 23 of datasheet. Controls speed of printing and darkness
Unless otherwise stated, this code is released under the MIT License – Please use, change and share it.

Changing heatTime and heatInterval to lower values, will yield a faster, but lighter printing, and raising them will yield a slower, but darker printing. If you are running off of 5V, and find the printing too light, try changing both values to 255.

You can make changes to the file with the arduino sketch open. Just save the Thermal.cpp file and re-upload the sketch to see the changes.

Help expand the library

We would love help expanding the library if you are interested. We would like to add to support for bitmap printing and other text setting. Also there may be a better way to set many of the settings than we are now. If you are interested in helping, let us know in the forum.

« Older Entries