Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver0804 committed Dec 19, 2023
0 parents commit bcc4c55
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 0 deletions.
184 changes: 184 additions & 0 deletions ASCII_UNO.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#include <Wire.h>
int count = 0;

const int startPin = 2; // Start pin number for digital pins
const int endPin = 13; // End pin number for digital pins
char pinStatuses[endPin - startPin + 1]; // Array to store the statuses of pins (H/L)
float voltageReadings[4]; // Array to store voltage readings for analog pins

const int maxDevices = 3; // Maximum number of I2C devices
byte foundDevices[maxDevices]; // Array to store addresses of found I2C devices
int deviceCount = 0; // Number of found I2C devices

// Reads and saves the status of each digital pin
void readAndSavePinStatuses() {
for (int i = startPin; i <= endPin; i++) {
pinStatuses[i - startPin] = digitalRead(i) == HIGH ? 'H' : 'L';
}
}

// Reads the voltages from the analog pins and saves them
void readAnalogVoltages() {
for (int pin = A0; pin <= A3; pin++) {
int sensorValue = analogRead(pin);
voltageReadings[pin - A0] = sensorValue * 5.0 / 1023.0;
}
}

// Scans and identifies I2C devices on the bus
void scanI2CDevices() {
byte error, address;
deviceCount = 0; // Reset the device count

for (address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0 && deviceCount < maxDevices) {
foundDevices[deviceCount++] = address;
}
}
}
// Prints an ASCII loading animation based on the frame count
void printLoadingAnimation(int frame) {
switch (frame % 4) { // Loop through 4 different frames
case 0:
Serial.print(" - ");
break;
case 1:
Serial.print(" \\ ");
break;
case 2:
Serial.print(" I ");
break;
case 3:
Serial.print(" / ");
break;
}
}

// Function to print a voltage value
void printVoltage(float voltage) {
Serial.print(voltage);
Serial.print(" V <-\t");
}

// Function to print a pin status
void printPinStatus(char status) {
if (status == 'H') {
Serial.print("\033[31mH\033[0m");
} else {
Serial.print("\033[32mL\033[0m");
}
}

void setup() {
Serial.begin(115200);
// Set all digital pins to INPUT_PULLUP
for (int i = startPin; i <= endPin; i++) {
pinMode(i, INPUT_PULLUP);
}
Wire.begin(); // Initialize I2C
Serial.print("\033[2J");
}

void loop() {
// Main loop of the program
readAndSavePinStatuses(); // Read and save digital pin statuses
readAnalogVoltages(); // Read analog voltages
scanI2CDevices(); // Scan for I2C devices

// Clear the screen and move the cursor to the top-left corner
//Serial.print("\033[2J");
Serial.print("\033[H");

Serial.println(" \t");
Serial.println(" \t");
Serial.println(" \t\t +-----+");
Serial.println(" \t\t+----[PWR]-------------------| USB |--+");
Serial.println(" \t\t| +-----+ |");
Serial.println(" \t\t| GND/RST2 [G][E] |");
Serial.print(" \t\t| MOSI2/SCK2 [");
printPinStatus(pinStatuses[11 - startPin]);
Serial.print("][");
printPinStatus(pinStatuses[13 - startPin]);
Serial.println("] A5/SCL[\033[33mC\033[0m] | C5 ");
Serial.print(" \t\t| 5V/MISO2 [5][");
printPinStatus(pinStatuses[12 - startPin]);
Serial.println("] A4/SDA[\033[33mC\033[0m] | C4 ");
Serial.println(" \t\t| AREF[A] |");
Serial.println(" \t\t| GND[G] |");
Serial.print(" \t\t| [ ]N/C SCK/13[");
printPinStatus(pinStatuses[13 - startPin]);
Serial.println("] | B5");
Serial.print(" \t\t| [ ]IOREF MISO/12[");
printPinStatus(pinStatuses[12 - startPin]);
Serial.println("] | .");
Serial.print(" \t\t| [R]RST MOSI/11[");
printPinStatus(pinStatuses[11 - startPin]);
Serial.println("]~| .");
Serial.print(" \t\t| [3]3V3 +---+ 10[");
printPinStatus(pinStatuses[10 - startPin]);
Serial.println("]~| .");
Serial.print(" \t\t| [5]5v -| A |- 9[");
printPinStatus(pinStatuses[9 - startPin]);
Serial.println("]~| .");
Serial.print(" \t\t| [G]GND -| R |- 8[");
printPinStatus(pinStatuses[8 - startPin]);
Serial.println("] | B0");
Serial.println(" \t\t| [G]GND -| D |- |");
Serial.print(" \t\t| [I]Vin -| U |- 7[");
printPinStatus(pinStatuses[7 - startPin]);
Serial.println("] | D7");
Serial.print(" \t\t| -|");
printLoadingAnimation(count++);
Serial.print("|- 6[");
printPinStatus(pinStatuses[6 - startPin]);
Serial.println("]~| .");
Serial.print(" ");
printVoltage(voltageReadings[0]);
Serial.print("| [\033[91mA\033[0m]A0 -| N |- 5[");
printPinStatus(pinStatuses[5 - startPin]);
Serial.println("]~| .");
Serial.print(" ");
printVoltage(voltageReadings[1]);
Serial.print("| [\033[91mA\033[0m]A1 -| O |- 4[");
printPinStatus(pinStatuses[4 - startPin]);
Serial.println("] | .");
Serial.print(" ");
printVoltage(voltageReadings[2]);
Serial.print("| [\033[91mA\033[0m]A2 +---+ INT1/3[");
printPinStatus(pinStatuses[3 - startPin]);
Serial.println("]~| .");
Serial.print(" ");
printVoltage(voltageReadings[3]);
Serial.print("| [\033[91mA\033[0m]A3 INT0/2[");
printPinStatus(pinStatuses[2 - startPin]);
Serial.println("] | .");
Serial.println(" \t\t| [\033[33mC\033[0m]A4/SDA RST SCK MISO TX>1[T] | .");
Serial.print(" \t\t| [\033[33mC\033[0m]A5/SCL [R] [");
printPinStatus(pinStatuses[13 - startPin]);
Serial.print("] [");
printPinStatus(pinStatuses[12 - startPin]);
Serial.println("] RX<0[R] | D0");
Serial.print(" \t\t| [G] [");
printPinStatus(pinStatuses[11 - startPin]);
Serial.println("] [5] |");
Serial.println(" \t\t| UNO_R3 GND MOSI 5V ____________/");
Serial.println(" \t\t \\_______________________/");


// Print I2C device addresses
if (deviceCount > 0) {
Serial.println("\t\tFound I2C device(s) at address(es):");
for (int i = 0; i < deviceCount; i++) {
Serial.print("\t\t0x");
if (foundDevices[i] < 16) Serial.print("0");
Serial.print(foundDevices[i], HEX);
}
} else {
Serial.println("\t\tNo I2C devices found.");
}

//delay(100);
}
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# AsciiDuinoDisplay
![image](./pic/AsciiDuinoDisplay.gif)

## Introduction
AsciiDuinoDisplay is an innovative project dedicated to bringing ASCII art to life on Arduino UNO. This project harnesses the simplicity of ASCII art and the versatility of Arduino to create dynamic, visually appealing displays using just characters. It's perfect for hobbyists, educators, and anyone interested in exploring the intersection of art and technology.

## Features
- Dynamic ASCII art rendering on Arduino UNO.
- Real-time ASCII art updates based on sensor inputs.

## Getting Started
### Prerequisites
- An Arduino UNO board.
- Arduino IDE installed on your computer ([Download here](https://www.arduino.cc/en/Main/Software)).
- A USB cable to connect the Arduino to your computer.

### Installation
1. Clone this repository or download the source code.
2. Open the `.ino` file using the Arduino IDE.
3. Connect your Arduino UNO to your computer using the USB cable.
4. Select the correct board and port in the Arduino IDE.
5. Upload the sketch to your Arduino UNO.

## Usage
Once the sketch is uploaded, the Arduino will start displaying ASCII art.

### Viewing ASCII Art
To view the ASCII art in its intended format, we recommend using a terminal emulator that supports ANSI escape sequences, such as PuTTY or Tera Term. The Arduino IDE's built-in Serial Monitor does not support these sequences, which might result in incorrect display formatting.

#### Configuring PuTTY for Best Results
1. Download and open PuTTY ([Download here](https://www.putty.org/)).
2. In the 'Session' category, select 'Serial', and enter the correct COM port for your Arduino.
3. Under 'Connection > Serial', set the baud rate to match the rate in your Arduino sketch (usually 115200).
4. Open the connection and enjoy the ASCII art display.

## Contributing
Contributions to AsciiDuinoDisplay are always welcome. Whether it's bug fixes, feature enhancements, or documentation improvements, feel free to fork this repository and submit a pull request.

## Acknowledgments
- Thanks to the Arduino community for continuous inspiration and support. (http://busyducks.com/wp_4_1/2015/11/16/ascii-art-arduino-pinouts/)
- Special thanks to [ASCII Art Archive](https://www.asciiart.eu/) for providing a wide array of ASCII art examples.

---

**Note:** This project is intended for educational and hobbyist purposes and is not suited for commercial use.
Binary file added pic/AsciiDuinoDisplay.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pic/AsciiDuinoDisplay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bcc4c55

Please sign in to comment.