# Pi...In a Single Digit

3,195

4

7

Published

## Introduction: Pi...In a Single Digit

Ah yes. It has been a long time since I posted an Instructable...well here goes:

It has been a while since I have been otivated to write an 'ible. During this idle time I have been writing, rewriting and editing code as well as designing lots of PCBs.

For my new ible which I have refined the code for I have made the Arduino Uno display pi one digit at a time I only went so far.(depending on how many digits you are willing to copy, paste and edit you can have more or less. )

So, let's build it!

## Step 1: Parts, Parts, Parts

You will need:
1 Arduino Uno
1 Single Digit Seven Segment Display (Try to get common cathode. If you don't you will need the transistors.)
7 Transistors (I used these to drive the single digit seven segment. If you got common anode then you need these.)
7 1K resistors( You will need these if you have transistors.)

Definitions:
Common anode: All the pins have the positive lead in common.

## Step 2: A Bit of Theory Before Moving On.

A common anode seven segment is a bit harder to use and is less welcome in a world of common cathode. Common anode is reversed compared to common cathode. Therefore, everything is the inverse. On means off and off means on. (see my 'ible on Sinking and Sourcing) Therefore we place a transistor to drive it allowing it to be common anode but we cannot omit the resistor (All 1Kohm on the base pin of the transistor because to prevent the transistors from pulling too much current and burning the ATMega328(Guess how I know this.)

## Step 3: Programming.

I tested every pin and wrote the code in a way I would understand. Here is how I did it:

T1=Pin 7=E
T2=Pin 8=D
T3=Pin 9=C
T4=Pin 10=G
T5=Pin 11=F
T6=Pin 12=A
T7=Pin13=B

The T's indicate the transistor numbers like on the page before or the page after this one. The A,B,C,D,E,F,G are standardized seven segment letters. Above I have standardized seven segment letter names for your reference.

Upload this code to the Arduino:

```/*

The Octopi is a device that displays one digit of pi for a certain amount of time before it repeats. Dashes define the end of the string before repeat...you could always add more digits to the string...

*/
//A string simplifies and complicates life. But I used one anyways.

String pi = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778---";

int needtoloop = pi.length();//checking length of pi:-)Okay just the string...

//Let's define some pins!
int T1 = 7;
int T2 = 8;
int T3 = 9;
int T4 = 10;
int T5 = 11;
int T6 = 12;
int T7 = 13;

void setup(){
pinMode (T1,OUTPUT);
pinMode (T2,OUTPUT);
pinMode (T3,OUTPUT);
pinMode (T4,OUTPUT);
pinMode (T5,OUTPUT);
pinMode (T6,OUTPUT);
pinMode (T7,OUTPUT);
}

void loop() {
pinitiate();
}

void pinitiate(){ //get it pi initiate? No? Oh well...back to the joke book.
for (int n = 0; n < needtoloop; n++){
if (pi.charAt(n)=='0') {
digitalWrite(T6, HIGH);
digitalWrite(T5, HIGH);
digitalWrite(T7, HIGH);
digitalWrite(T1, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T2, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T6, LOW);
digitalWrite(T5, LOW);
digitalWrite(T7, LOW);
digitalWrite(T1, LOW);
digitalWrite(T3, LOW);
digitalWrite(T2, LOW);
//   pinitiate();
}
else if (pi.charAt(n)=='1') {
digitalWrite(T7, HIGH);
digitalWrite(T3, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T7, LOW);
digitalWrite(T3, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='2') {
digitalWrite(T6, HIGH);
digitalWrite(T7, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T1, HIGH);
digitalWrite(T2, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T6, LOW);
digitalWrite(T7, LOW);
digitalWrite(T4, LOW);
digitalWrite(T1, LOW);
digitalWrite(T2, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='3') {
digitalWrite(T6, HIGH);
digitalWrite(T7, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T2, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T6, LOW);
digitalWrite(T7, LOW);
digitalWrite(T4, LOW);
digitalWrite(T3, LOW);
digitalWrite(T2, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='4') {
digitalWrite(T5, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T7, HIGH);
digitalWrite(T3, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T5, LOW);
digitalWrite(T4, LOW);
digitalWrite(T7, LOW);
digitalWrite(T3, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='5') {
digitalWrite(T6, HIGH);
digitalWrite(T5, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T2, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T6, LOW);
digitalWrite(T5, LOW);
digitalWrite(T4, LOW);
digitalWrite(T3, LOW);
digitalWrite(T2, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='6') {
digitalWrite(T6, HIGH);
digitalWrite(T5, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T2, HIGH);
digitalWrite(T1, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T6, LOW);
digitalWrite(T5, LOW);
digitalWrite(T4, LOW);
digitalWrite(T3, LOW);
digitalWrite(T2, LOW);
digitalWrite(T1, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='7') {
digitalWrite(T5, HIGH);
digitalWrite(T6, HIGH);
digitalWrite(T7, HIGH);
digitalWrite(T3, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T5, LOW);
digitalWrite(T6, LOW);
digitalWrite(T7, LOW);
digitalWrite(T3, LOW);
//  pinitiate();
}
else if (pi.charAt(n)=='8') {
digitalWrite(T1, HIGH);
digitalWrite(T2, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T5, HIGH);
digitalWrite(T6, HIGH);
digitalWrite(T7, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T1, LOW);
digitalWrite(T2, LOW);
digitalWrite(T3, LOW);
digitalWrite(T4, LOW);
digitalWrite(T5, LOW);
digitalWrite(T6, LOW);
digitalWrite(T7, LOW);
//   pinitiate();
}
else if (pi.charAt(n)=='9') {
digitalWrite(T2, HIGH);
digitalWrite(T3, HIGH);
digitalWrite(T4, HIGH);
digitalWrite(T5, HIGH);
digitalWrite(T6, HIGH);
digitalWrite(T7, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T2, LOW);
digitalWrite(T3, LOW);
digitalWrite(T4, LOW);
digitalWrite(T5, LOW);
digitalWrite(T6, LOW);
digitalWrite(T7, LOW);
//   pinitiate();
}
else if (pi.charAt(n)=='-') {
digitalWrite(T4, HIGH);
delay(1000); //Let's give ourselves one second to read the number
digitalWrite(T4, LOW);
// pinitiate();

}

}

}

```

## Step 4: Build.

Although there may not be resistors in my pictures they are certainly a necessity if you have transistors. Resistors are also a necessity if you are using a common cathode display to prevent the LEDs from burning themselves out.

So in the end resistors are essential.

Build according to the schematic. I used a bread board. Depending on my mood I might use perf board or even print a whole PCB...that will be coming soon.

## Step 5: Done!

You have now reached completion of your single digit pi viewer!

I hope you enjoyed this Instructable.

## Recommendations

• ### Arduino Class

70,827 Enrolled

## 7 Discussions

Thanks! I actually tried doing more (like triple the amount) and it wouldn't compile...or upload.

I actually used parts of your POV instructable (if statements) to go and speed up the code writing process.

When I saw your comment I laughed because I had just been thinking of the same thing. I thought maybe I could have the Arduino generate triangles so thin they would form a circle when bound. Then it could calculate a pretty exact circumference and probably...wait, that's probably going to take extreme coding and a pretty powerful processor.

No , it probably wouldn't be possible.

But if you're willing to take up the challenge by all means go ahead. If you do ending up making something be sure to share!

After posting that comment, I thought a bit, and read the wiki article on pi - and now think that it wouldnt be possible :)