Category Archives: Science

Holiday Fairy Christmas Light String Teardown

Teardown and exploration of how a string of fairy lights/Christmas lights/holiday lights works. Part of the Project Rankin series that intends to build a holiday ornament powered by the AC electricity in a light strand.

Watch the complete Project Rankin

Music by Anders Enger Jensen

How To Set Up A TFT Screen On Arduino With The RA8875

In a previous video, we looked at how to attach a TFT LCD screen to a Raspberry Pi to build a small-form-factor project. But what if your project doesn’t need quite as much horsepower? What if you just need to display shapes and colors on a screen with no operating system and nearly instant boot times? This is where a TFT LCD screen on Arduino comes in handy. In this video, we’ll look at how to set up a TFT LCD screen on Arduino with the RA8875 breakout board from Adafruit then walk through how to display various shapes and colors in the sketch.

PARTS/TOOLS:

(Most of these can be found in the Arduino Starter Kit available here)

Arduino UNO

Solderless breadboard

Jumper (Dupont) Wire

TFT LCD Display

Adafruit RA8875 Breakout Board

RESOURCES:

RA8875 Datasheet

Adafruit RA8875 Arduino Library

THE CIRCUIT:

It’s a fairly simple wiring job here using the hardware SPI interface on the Arduino. CLK, MISO, and MOSI connect to 13, 12, 11 respectively. CS, RST, and INT are defaulted to 10, 9, and 3, but can be reassigned in the sketch. Of course, the display is not illustrated, but it is connected to the 40-pin ribbon connector on the left.

THE SKETCH:

/******************************************************************
 This is an example for the Adafruit RA8875 Driver board for TFT displays
 ---------------> http://www.adafruit.com/products/1590
 The RA8875 is a TFT driver for up to 800x480 dotclock'd displays
 It is tested to work with displays in the Adafruit shop. Other displays
 may need timing adjustments and are not guanteed to work.

 Adafruit invests time and resources providing this open
 source code, please support Adafruit and open-source hardware
 by purchasing products from Adafruit!

 Written by Limor Fried/Ladyada for Adafruit Industries.
 BSD license, check license.txt for more information.
 All text above must be included in any redistribution.
 ******************************************************************/

#include 
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"


// Library only supports hardware SPI at this time
// Connect SCLK to UNO Digital #13 (Hardware SPI clock)
// Connect MISO to UNO Digital #12 (Hardware SPI MISO)
// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
#define RA8875_INT 3
#define RA8875_CS 10
#define RA8875_RESET 9

Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;

void setup()
{
  Serial.begin(9600);
  Serial.println("RA8875 start");

  /* Initialize the display using 'RA8875_480x80', 'RA8875_480x128', 'RA8875_480x272' or 'RA8875_800x480' */
  if (!tft.begin(RA8875_480x272)) {
    Serial.println("RA8875 Not Found!");
    while (1);
  }

  Serial.println("Found RA8875");

  tft.displayOn(true);
  tft.GPIOX(true);      // Enable TFT - display enable tied to GPIOX
  tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
  tft.PWM1out(255);

  // With hardware accelleration this is instant
  tft.fillScreen(RA8875_WHITE);

  // Play with PWM
  for (uint8_t i=255; i!=0; i-=5 )
  {
    tft.PWM1out(i);
    delay(10);
  }
  for (uint8_t i=0; i!=255; i+=5 )
  {
    tft.PWM1out(i);
    delay(10);
  }
  tft.PWM1out(255);

  tft.fillScreen(RA8875_RED);
  delay(500);
  tft.fillScreen(RA8875_YELLOW);
  delay(500);
  tft.fillScreen(RA8875_GREEN);
  delay(500);
  tft.fillScreen(RA8875_CYAN);
  delay(500);
  tft.fillScreen(RA8875_MAGENTA);
  delay(500);
  tft.fillScreen(RA8875_BLACK);

  // Try some GFX acceleration!
  tft.drawCircle(100, 100, 50, RA8875_BLACK);
  tft.fillCircle(100, 100, 49, RA8875_GREEN);

  tft.fillRect(11, 11, 398, 198, RA8875_BLUE);
  tft.drawRect(10, 10, 400, 200, RA8875_GREEN);
  tft.fillRoundRect(200, 10, 200, 100, 10, RA8875_RED);
  tft.drawPixel(10,10,RA8875_BLACK);
  tft.drawPixel(11,11,RA8875_BLACK);
  tft.drawLine(10, 10, 200, 100, RA8875_RED);
  tft.drawTriangle(200, 15, 250, 100, 150, 125, RA8875_BLACK);
  tft.fillTriangle(200, 16, 249, 99, 151, 124, RA8875_YELLOW);
  tft.drawEllipse(300, 100, 100, 40, RA8875_BLACK);
  tft.fillEllipse(300, 100, 98, 38, RA8875_GREEN);
  // Argument 5 (curvePart) is a 2-bit value to control each corner (select 0, 1, 2, or 3)
  tft.drawCurve(50, 100, 80, 40, 2, RA8875_BLACK);
  tft.fillCurve(50, 100, 78, 38, 2, RA8875_WHITE);

  pinMode(RA8875_INT, INPUT);
  digitalWrite(RA8875_INT, HIGH);

  tft.touchEnable(true);

  Serial.print("Status: "); Serial.println(tft.readStatus(), HEX);
  Serial.println("Waiting for touch events ...");
}

void loop()
{
  float xScale = 1024.0F/tft.width();
  float yScale = 1024.0F/tft.height();

  /* Wait around for touch events */
  if (! digitalRead(RA8875_INT))
  {
    if (tft.touched())
    {
      Serial.print("Touch: ");
      tft.touchRead(&tx, &ty);
      Serial.print(tx); Serial.print(", "); Serial.println(ty);
      /* Draw a circle */
      tft.fillCircle((uint16_t)(tx/xScale), (uint16_t)(ty/yScale), 4, RA8875_WHITE);
    }
  }
}

Driving LED Displays With Arduino And MAX7219

The Arduino platform is great for making LEDs blink and driving small displays, but what happens when you need to display more complex information? For Project ColorTyme, I need to drive 6x 14-segment “starburst” style alphanumeric LED displays, but pins are at a premium. To solve the problem, we’ll incorporate the MAX7219 LED display driver; however, it’s an imperfect solution: The displays I’m using are common-anode while the MAX7219 is a common-cathode driver. In this video, we’ll walk through wiring a 14-segment display to the Arduino, then wiring the MAX7219 to drive in common-anode mode while adjusting the code so everything comes out correctly.

PARTS/TOOLS:

(Most of these can be found in the Arduino Starter Kit available here)

Arduino UNO

Solderless breadboard

Jumper (Dupont) Wire

MAX7219 LED Driver

14 Segment LED Display

RESOURCES:

MAX7219 Datasheet

LedControl Arduino Library (patched for common-anode displays)

THE CIRCUIT:

The main thing to remember when wiring in this inverse method is that the segment pins correspond to individual digits while the digit pins correspond to individual segments. This illustration is also limited to a single 14-segment digit, but the pinout for a dual display is what is wired.

THE SKETCH:

//Project ColorTyme
//MAX7219x14-segment Display Proof of Concept
//CC-BY-SA Matthew Eargle
//element14 Presents http://element14.com/presents
//AirborneSurfer Productions http://airbornesurfer.com

#include "LedControl.h"
/*
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=100;
byte numbers[16] = {
B11111100, B01100000, B11011010, B11110010,
B01100110, B10110110, B10111110, B11100000,
B11111110, B11110110, B11101110, B11110011,
B10011100, B11110001, B10011110, B10001110
};
int ones = 0;
int twos = 0;

void setup() {
/*
MAX72XX wakeup call
/
lc.shutdown(0,false);
/
set the brightness /
lc.setIntensity(0,1);
/
clear the display */
lc.clearDisplay(0);
int counter = 0;
}

void loop() {
lc.setColumn(0,2,numbers[twos]);
while(ones <= 15) {
lc.setColumn(0,1,numbers[ones]);
delay(1000);
ones++;
};
ones = 0;
twos++;
}

How To Build A Battery Backup Real-Time Clock

Previously, we looked at how to build a simple DIY Arduino clock. Unfortunately, if power to the clock is disconnected, the whole thing has to be reset. To solve that problem, we’re going to add an Arduino battery backup real time clock module based on the DS1307 RTC package. Instead of purchasing a pre-made part, we’ll walk through how to build a DIY Arduino RTC module from scratch and add it to our clock project.

PARTS/TOOLS:

(Most of these can be found in the Arduino Starter Kit available here)

Arduino UNO

1602 LCD

Solderless breadboard

Assorted resistors (220 and 10K, specifically)

Jumper (Dupont) Wire

10K Potentiometer

Tactile switches

DS1307 Real Time Clock

32.768kHz Crystal Oscillator

Coin Cell Holder

CR2032 Coin Cell Battery

RESOURCES:

DS1307 Datasheet

RealTimeClockDS1307 Arduino Library

THE CIRCUIT:

Assemble the LCD circuit as described in previous projects. Connect the DS1307 pins as indicated in the following illustration:

THE SKETCH:

#include
#include

//RealTimeClock RTC;//=new RealTimeClock();

#define Display_Clock_Every_N_Seconds 10 // n.secs to show date/time
#define Display_ShortHelp_Every_N_Seconds 60 // n.secs to show hint for help
//#define TEST_Squarewave
//#define TEST_StopStart
//#define TEST_1224Switch

int count=0;
char formatted[] = "00-00-00 00:00:00x";

void setup() {
// Wire.begin();
Serial.begin(9600);
pinMode(A3, OUTPUT); //*** pin 16 (Analog pin 2) as OUTPUT ***
digitalWrite(A3, HIGH); //*** pin 16 (Analog pin 2) set to LOW ***
pinMode(A2, OUTPUT); //*** pin 17 (Analog pin 3) as OUTPUT ***
digitalWrite(A2, LOW); //*** pin 17 (Analog pin 3) set to HIGH ***
//*** Analog Pin settings to power RTC module ***
}

void loop() {
if(Serial.available())
{
processCommand();
}

RTC.readClock();
count++;
if(count % Display_Clock_Every_N_Seconds == 0){
Serial.print(count);
Serial.print(": ");
RTC.getFormatted(formatted);
Serial.print(formatted);
Serial.println();
}

if(count % Display_ShortHelp_Every_N_Seconds == 0) {
Serial.println("Send ? for a list of commands.");
}
#ifdef TEST_Squarewave
if(count%10 == 0)
{
switch(count/10 % 6)
{
case 0:
Serial.print("Squarewave disabled (low impedance): ");
RTC.sqwDisable(0);
Serial.println((int) RTC.readData(7));
break;
case 1:
Serial.print("Squarewave disabled (high impedance): ");
RTC.sqwDisable(1);
Serial.println((int) RTC.readData(7));
break;
case 2:
Serial.println("Squarewave enabled at 1 Hz");
RTC.sqwEnable(RTC.SQW_1Hz);
break;
case 3:
Serial.println("Squarewave enabled at 4.096 kHz");
RTC.sqwEnable(RTC.SQW_4kHz);
break;
case 4:
Serial.println("Squarewave enabled at 8.192 kHz");
RTC.sqwEnable(RTC.SQW_8kHz);
break;
case 5:
Serial.println("Squarewave enabled at 32.768 kHz");
RTC.sqwEnable(RTC.SQW_32kHz);
break;
default:
Serial.println("Squarewave test not defined");
}//switch
}
#endif

#ifdef TEST_StopStart
if(count%10 == 0)
{
if(!RTC.isStopped())
{
if(RTC.getSeconds() < 45)
{
Serial.println("Stopping clock for 10 seconds");
RTC.stop();
}//if we have enough time
} else {
RTC.setSeconds(RTC.getSeconds()+11);
RTC.start();
Serial.println("Adding 11 seconds and restarting clock");
}
}//if on a multiple of 10 counts
#endif

#ifdef TEST_1224Switch
if(count%10 == 0)
{
if(count %20 == 0)
{
Serial.println("switching to 12-hour time");
RTC.switchTo12h();
RTC.setClock();
}
else
{
Serial.println("switching to 24-hour time");
RTC.switchTo24h();
RTC.setClock();
}
}
#endif
}

void processCommand() {
if(!Serial.available()) { return; }
char command = Serial.read();
int in,in2;
switch(command)
{
case 'H':
case 'h':
in=SerialReadPosInt();
RTC.setHours(in);
RTC.setClock();
Serial.print("Setting hours to ");
Serial.println(in);
break;
case 'I':
case 'i':
in=SerialReadPosInt();
RTC.setMinutes(in);
RTC.setClock();
Serial.print("Setting minutes to ");
Serial.println(in);
break;
case 'S':
case 's':
in=SerialReadPosInt();
RTC.setSeconds(in);
RTC.setClock();
Serial.print("Setting seconds to ");
Serial.println(in);
break;
case 'Y':
case 'y':
in=SerialReadPosInt();
RTC.setYear(in);
RTC.setClock();
Serial.print("Setting year to ");
Serial.println(in);
break;
case 'M':
case 'm':
in=SerialReadPosInt();
RTC.setMonth(in);
RTC.setClock();
Serial.print("Setting month to ");
Serial.println(in);
break;
case 'D':
case 'd':
in=SerialReadPosInt();
RTC.setDate(in);
RTC.setClock();
Serial.print("Setting date to ");
Serial.println(in);
break;
case 'W':
Serial.print("Day of week is ");
Serial.println((int) RTC.getDayOfWeek());
break;
case 'w':
in=SerialReadPosInt();
RTC.setDayOfWeek(in);
RTC.setClock();
Serial.print("Setting day of week to ");
Serial.println(in);
break;

case 't':
case 'T':
if(RTC.is12hour()) {
RTC.switchTo24h();
Serial.println("Switching to 24-hour clock.");
} else {
RTC.switchTo12h();
Serial.println("Switching to 12-hour clock.");
}
RTC.setClock();
break;

case 'A':
case 'a':
if(RTC.is12hour()) {
RTC.setAM();
RTC.setClock();
Serial.println("Set AM.");
} else {
Serial.println("(Set hours only in 24-hour mode.)");
}
break;

case 'P':
case 'p':
if(RTC.is12hour()) {
RTC.setPM();
RTC.setClock();
Serial.println("Set PM.");
} else {
Serial.println("(Set hours only in 24-hour mode.)");
}
break;

case 'q':
RTC.sqwEnable(RTC.SQW_1Hz);
Serial.println("Square wave output set to 1Hz");
break;
case 'Q':
RTC.sqwDisable(0);
Serial.println("Square wave output disabled (low)");
break;

case 'z':
RTC.start();
Serial.println("Clock oscillator started.");
break;
case 'Z':
RTC.stop();
Serial.println("Clock oscillator stopped.");
break;

case '>':
in=SerialReadPosInt();
in2=SerialReadPosInt();
RTC.writeData(in, in2);
Serial.print("Write to register ");
Serial.print(in);
Serial.print(" the value ");
Serial.println(in2);
break;
case '<':
in=SerialReadPosInt();
in2=RTC.readData(in);
Serial.print("Read from register ");
Serial.print(in);
Serial.print(" the value ");
Serial.println(in2);
break;

default:
Serial.println("Unknown command. Try these:");
Serial.println(" h## - set Hours [range 1..12 or 0..24]");
Serial.println(" i## - set mInutes [range 0..59]");
Serial.println(" s## - set Seconds [range 0..59]");
Serial.println(" d## - set Date [range 1..31]");
Serial.println(" m## - set Month [range 1..12]");
Serial.println(" y## - set Year [range 0..99]");
Serial.println(" w## - set arbitrary day of Week [range 1..7]");
Serial.println(" t - toggle 24-hour mode");
Serial.println(" a - set AM p - set PM");
Serial.println();
Serial.println(" z - start clock Z - stop clock");
Serial.println(" q - SQW/OUT = 1Hz Q - stop SQW/OUT");
Serial.println();
Serial.println(" >##,### - write to register ## the value ###");
Serial.println(" <## - read the value in register ##");

}//switch on command

}

//read in numeric characters until something else
//or no more data is available on serial.
int SerialReadPosInt() {
int i = 0;
boolean done=false;
while(Serial.available() && !done)
{
char c = Serial.read();
if (c >= '0' && c <='9')
{
i = i * 10 + (c-'0');
}
else
{
done = true;
}
}
return i;
}

How To Build An Arduino Clock

Clocks are a rite of passage for hardware hackers, and with this video you can start working on your DIY Clock merit badge using the Arduino platform to build a basic Arduino clock. This project builds on the Arduino Fortune Teller project from the “Arduino For Kooks” basic series and teaches programming concepts like timing and actively updating a display, so you can use it as a springboard for many more complicated projects!

PARTS/TOOLS:

(Most of these can be found in the Arduino Starter Kit available here)

Arduino UNO

1602 LCD

Solderless breadboard

Assorted resistors (220 and 10K, specifically)

Jumper (Dupont) Wire

10K Potentiometer

Tactile switches

The Circuit:

Connect the LCD module as described in the Liquid Crystal Ball project. You can use the breadboard to create buses for +5V and GND. Connect one side of one tactile switch to D8 and the other to a 10K resistor to ground. Connect one side of the other tactile switch to D9 and the other side to a 10K resistor to ground.

The Sketch:

//Projet ColorTyme
//Phase 1: Simple LCD Clock
//CC-BY-SA Matthew Eargle
//AirborneSurfer.com
//element14 Presents

#include "LiquidCrystal.h"

// Define LCD pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// initial Time display is 00:00:00 (24hr clock)
int h=00;
int m=00;
int s=00;

// Time Set Buttons
int button1;
int button2;
int hs=8;// pin 8 for Hours Setting
int ms=9;// pin 9 for Minutes Setting

// Digital LCD Constrast setting
int cs=6;// pin 5 for contrast PWM
static int contrast=100;// default contrast

//Define current time as zero
static uint32_t last_time, now = 0;

void setup()
{
lcd.begin(16,2);
pinMode(hs,INPUT_PULLUP);
pinMode(ms,INPUT_PULLUP);

now=millis(); // read RTC initial value
analogWrite(cs,contrast);
}

void loop()
{
// Update LCD Display
// Print TIME in Hour, Min, Sec
lcd.setCursor(0,0);
lcd.print("Time ");
if(h<10)lcd.print("0");// always 2 digits
lcd.print(h);
lcd.print(":");
if(m<10)lcd.print("0");
lcd.print(m);
lcd.print(":");
if(s<10)lcd.print("0");
lcd.print(s);


lcd.setCursor(0,1);// for Line 2
lcd.print("SURF STD TIME");

while ((now-last_time) < 1000 ) // wait1000ms
{
now=millis();
}

last_time=now; // prepare for next loop
s=s+1; //increment sec. counting


/-------Time setting-------/
button1=digitalRead(hs);
if(button1==0)
{
s=0;
h=h+1;
}

button2=digitalRead(ms);
if(button2==0){
s=0;
m=m+1;
}

analogWrite(cs,contrast); // update contrast

/* ---- manage seconds, minutes, hours am/pm overflow ----*/
if(s==60){
s=0;
m=m+1;
}
if(m==60)
{
m=0;
h=h+1;
}
if (h==25)
{
h=0;
}

}

How Hex Color Codes Work

Where does one person’s interpretation of a color end and another person’s begin? How do we universally define colors displayed on modern screens? What is the equivalent of Pantone for digital documents? In this video, we’ll explore how color is displayed on modern LCD/LED screens before going into depth on how hexadecimal color codes work as a technological standard to convey color information.

Get the Arduino code, bill of materials, and more on element14.com/presents

Check out the rest of Project ColorTyme here

This video is part of a project for the element14 community. The electronics and engineering community where you can connect and collaborate with top engineers from around the world. Join now at element14 dot com, link in the doobly-doo!

Firebrick5 [#8E2323]

Picasso Blue [#0276FD]

Viridianlight [#6EFF70]

These are all very specific colors defined by very specific wavelengths of light, or–more accurately–by very specific ratios of three different specific wavelengths of light: red, blue, and green.

By varying the ratios of these three colors, we can create any color in the visible spectrum, but how do we tell all the millions of possible colors apart? We have definitive names for a few of them, sure, but when does one person’s interpretation of pumice [#78A489] end and blue fern [#759B84] begin?

We need some kind of universal language for defining colors. One that doesn’t leave any colors up to ambiguous interpretation. One that every modern device could conceivably understand and replicate. What we need are hex codes.

Greetings, Programs. Atari here, you there, and if you like learning about technology while building goofy projects around the shop, then go ahead and subscribe to this channel. Tally-ho!

Before we start talking about replicating colors, we should probably start by talking about how colors on a modern display are created. Most modern screens are made up of tiny picture elements–pixels–which are actually each made up of 3 color elements (or subpixels) that are each individually addressable.

Note that this is not the case when it comes to CRT displays. They employ an entirely different technology that we won’t be exploring in this video. If you want to learn about how CRT images are formed, Technology Connections has a fantastic piece all about it!

Anyway, pixels are each made up of 3 subpixels–one for each of the primary colors of light. By changing the intensity of each color’s respective subpixel, we can change the color of the pixel as observed by the human eye.

From red

To blue

To green

Or somewhere in between

Of course, if we turn everything up to full intensity, we’ll get white. Take everything down and we get black.

This is known as “additive color”: By adding more of a component color, we change the hue toward that component color.

Yes, this is a very rudimentary explanation of how additive color works, and I’m purposefully not going too in-depth because a discussion on color theory is really outside of the scope of this video. If you’re interested in that topic, leave me a note in the doobly-doo, and I’ll see what I can do. For now, I just want to provide a little context to facilitate the topic at hand.

Now, that brings me to the next point in this discussion. When we describe the capacity of a display to reproduce color information, we use a concept known as color depth. Color depth, or bit depth, is the number of bits used to indicate the color of a single pixel. As of 2018, nearly every display being manufactured is capable of displaying what’s known as “True Color” or 24-bit color. This means that every color the display is capable of reproducing can be defined by 24 bits or 3 bytes of information.

Are you still with me? Because this is where it all comes together.

Remember in the last video where we talked about how hexadecimal numbers work and why we use them in computing? You can watch the video up in the corner if you missed it.

Hexadecimal numbers work really well for computers because each digit holds 4 bits of information. If we put 2 hexadecimal digits together, we have a complete byte of information. That brings me back to these so-called “hex codes” for colors.

You may have noticed that hex codes are always six digits long. Six digits in hexadecimal is 3 bytes or 24 bits of information. So what do these codes mean? Let’s go back to 24-bit color.

We know that with 24 bit color, we have 3 bytes of color information. We also know that there are 3 primary colors of light represented by 3 subpixels in each pixel of the display. Are you starting to see a connection?

Now, you may–at some point–have seen a color indicated by an RGB value, a set of three numbers in parenthesis. This is a mathematical array that contains the respective intensities of the red, blue, and green subpixels. Each color’s intensity is represented by a decimal number between 0 and 255.

Why 255? Because it’s the largest decimal number that can be represented by 8 bits. That RGB value is actually a 24-bit number that’s written in an extremely clunky notation, but in engineering, we’re always looking for a way to make things more efficient. As such, we can fairly easily convert these three decimal numbers into three hexadecimal couplets and save quite a lot of typing down the road!

So in a hex code, each subpixel’s color is represented by a hexadecimal couplet: the first two digits are red, the next are blue, and the last two are green. By manipulating each couplet from double zero (zero intensity) to zero F (half intensity) to double F (full intensity), we can instruct a display to reproduce any of the 16 million 7 hundred 77 thousand 2 hundred 16 possible 24-bit colors.

Now for a fun fact: our squishy human eyes can only distinguish about 10 million different colors, so modern displays will actually reproduce more colors than we can possibly perceive, but those colors aren’t always evenly distributed across our perception space so some people will notice a phenomenon known as color banding at the transition between two adjacent colors. Light and perception is weird, man!

That, in a nutshell, is how hexadecimal codes work. Over the next several videos, I’ll be putting this information together with some electronics to build a rather interesting gadget, so be sure to subscribe and click the bell so you don’t miss out!

Connect with me on the social media and get sneak-peeks of projects in progress. Links are in the doobly-doo.

Up here is a video that YouTube thinks you’ll probably enjoy.

And the show notes for this episode are somewhere around here.

My name is Atari and until next time remember: It’s okay. It’s just a prototype.

Tally-ho, y’all!

How To Read Hexadecimal Numbers

Hexadecimal notation may look daunting, but with a little know-how and the right perspective, it can become extremely easy to learn how to read hex numbers. In this video, we’ll learn how to read hexadecimal numbers, how to count hexadecimal numbers, how to write hexadecimal numbers, and how to convert hexadecimal numbers.

Get the Arduino code, bill of materials, and more on element14.com/presents

Check out the rest of Project ColorTyme here

Arduino Basics Lesson 3-3: DIY Calculator

For the “Arduino For Kooks” course, I recommend you get the Arduino Starter Kit available here.

As we’ve learned throughout this series, a microcontroller like the one on the Arduino is basically a rudimentary computer that can execute instruction sets very quickly because it doesn’t have to load all those pesky applications and operating systems. What better capstone for this basic course than to combine everything that we’ve learned so far and build our own rudimentary mathematical computation device: a simple calculator!

For this calculator, we’re going to use a basic 4×4 matrix keypad and attach it to the Arduino in such a way that we only need to use 8 pins to cover the functions of 16 individual switches!

The Circuit:

Connect the character LCD and potentiometer as we learned in the Liquid Crystal Ball project, using the Arduino pins shown in the diagram. You can use a breadboard to create busses for +5V and GND.

Connect the pins of the keypad to pins D0-D8 on the Arduino as shown.

The Sketch:


#include //Header file for LCD from https://www.arduino.cc/en/Reference/LiquidCrystal
#include //Header file for Keypad from https://github.com/Chris--A/Keypad

const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns

// Define the Keymap
char keys[ROWS][COLS] = {

{'7','8','9','D'},
{'4','5','6','C'},
{'1','2','3','B'},
{'','0','#','A'}
};

byte rowPins[ROWS] = { 0, 1, 2, 3 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 4, 5, 6, 7 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Create the Keypad

const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 12, d7 = 13; //Pins to which LCD is connected
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

long Num1,Num2,Number;
char key,action;
boolean result = false;

void setup() {
lcd.begin(16, 2); //We are using a 16
2 LCD display
lcd.print("DIY Calculator"); //Display a intro message
lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print("-CircuitDigest"); //Display a intro message

delay(2000); //Wait for display to show info
lcd.clear(); //Then clean it
}

void loop() {

key = kpd.getKey(); //storing pressed key value in a char

if (key!=NO_KEY)
DetectButtons();

if (result==true)
CalculateResult();

DisplayResult();
}

void DetectButtons()
{
lcd.clear(); //Then clean it
if (key=='') //If cancel Button is pressed
{Serial.println ("Button Cancel"); Number=Num1=Num2=0; result=false;}

if (key == '1') //If Button 1 is pressed
{Serial.println ("Button 1");
if (Number==0)
Number=1;
else
Number = (Number
10) + 1; //Pressed twice
}

if (key == '4') //If Button 4 is pressed
{Serial.println ("Button 4");
if (Number==0)
Number=4;
else
Number = (Number10) + 4; //Pressed twice
}

if (key == '7') //If Button 7 is pressed
{Serial.println ("Button 7");
if (Number==0)
Number=7;
else
Number = (Number
10) + 7; //Pressed twice
}

if (key == '0')
{Serial.println ("Button 0"); //Button 0 is Pressed
if (Number==0)
Number=0;
else
Number = (Number10) + 0; //Pressed twice
}

if (key == '2') //Button 2 is Pressed
{Serial.println ("Button 2");
if (Number==0)
Number=2;
else
Number = (Number
10) + 2; //Pressed twice
}

if (key == '5')
{Serial.println ("Button 5");
if (Number==0)
Number=5;
else
Number = (Number10) + 5; //Pressed twice
}

if (key == '8')
{Serial.println ("Button 8");
if (Number==0)
Number=8;
else
Number = (Number
10) + 8; //Pressed twice
}

if (key == '#')
{Serial.println ("Button Equal");
Num2=Number;
result = true;
}

if (key == '3')
{Serial.println ("Button 3");
if (Number==0)
Number=3;
else
Number = (Number10) + 3; //Pressed twice
}

if (key == '6')
{Serial.println ("Button 6");
if (Number==0)
Number=6;
else
Number = (Number
10) + 6; //Pressed twice
}

if (key == '9')
{Serial.println ("Button 9");
if (Number==0)
Number=9;
else
Number = (Number10) + 9; //Pressed twice
}

if (key == 'A' || key == 'B' || key == 'C' || key == 'D') //Detecting Buttons on Column 4
{
Num1 = Number;
Number =0;
if (key == 'A')
{Serial.println ("Addition"); action = '+';}
if (key == 'B')
{Serial.println ("Subtraction"); action = '-'; }
if (key == 'C')
{Serial.println ("Multiplication"); action = '
';}
if (key == 'D')
{Serial.println ("Devesion"); action = '/';}

delay(100);
}
}

void CalculateResult()
{
if (action=='+')
Number = Num1+Num2;

if (action=='-')
Number = Num1-Num2;

if (action=='')
Number = Num1
Num2;

if (action=='/')
Number = Num1/Num2;
}

void DisplayResult()
{
lcd.setCursor(0, 0); // set the cursor to column 0, line 1
lcd.print(Num1); lcd.print(action); lcd.print(Num2);

if (result==true)
{lcd.print(" ="); lcd.print(Number);} //Display the result

lcd.setCursor(0, 1); // set the cursor to column 0, line 1
lcd.print(Number); //Display the result
}

Congratulations!

If you have completed all 9 lessons in this course, then you have completed the Arduino for Kooks basic-level course! You have learned most of the wiring and programming rudiments necessary to go on and build your very own projects with the Arduino platform!

As a reward for your efforts, I have designed a “merit badge” that you can attach to your EDC, patch wall, or a sweet hacker jacket. You’ve worked hard to achieve it, so show off your new skill set!

CLICK HERE TO ORDER YOUR BADGE

Arduino For Kooks Merit Badge

Congratulations on completing the Arduino for Kooks course in Arduino basics! As a reward for your efforts, you are eligible to wear this exclusive merit badge to show off your achievement and new skill set! This design is based on the Arduino Community Logo as I am not affiliated with Arduino the company. It’s going to be a hexagonal design so you can wear it with future badges in a sweet honeycomb design, but it looks just as good paired with other organizations’ badges, too!

The badge isn’t ready yet, but it will be soon! I’m working through the manufacturing process, and I will let you know once they’re ready! They’re going to measure about 1.5-2 inches across, and I’m looking to have the price point somewhere around $3US plus shipping, so let me know if you are interested in nabbing one of the first! You can check up on the progress via Instagram @theairbornesurfer

[yikes-mailchimp form=”1″ description=”1″ submit=”Let me know!”]

Arduino Basics Lesson 3-1: Ultrasonic DME

For the “Arduino For Kooks” course, I recommend you get the Arduino Starter Kit available here.

Now that we’ve learned the basics of digital and analog signalling on an Arduino, let’s start exploring with different kinds of sensors. The ultrasonic sensor module is a rudimentary SONAR device that emits and detects a particular high-frequency sound pulse. We can use this pulse to determine the location and relative position of objects.

The Circuit:

Using jumpers, connect +5V on the Arduino to VCC on the sensor and GND to GND. Connect the sensor’s Trigger and Echo pins to the Arduino at D2 and D4 respectively.

The Sketch:

const int trigPin = 2;
const int echoPin = 4;
void setup() {
Serial.begin(9600);}
void loop()
{
long duration, inches, cm;
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{return microseconds / 29 / 2;}