Presentation Advice

Hi all,

I'm looking for a way to break down a serial input, say the word "Test" for example, then convert that to a binary representation. But then I want to take these binary numbers and use them to turn a laser on and off through an UNO. I've gotten so far as to having whatever I input into the serial monitor convert to binary. But I cant figure out what I need to do in order to get any further. Any help would be greatly appreciated.

Define "further".

By get any further I mean I don't know what to do in order to break these binary outputs down. I tried to create an array in order to save the binary output into slots. But then I just end up with slots of 1101010, 0010110, and so on. But my way of thinking is I would need to break down each 1 and 0 independently in order to be able to output through the laser diode. That's where I get stuck, and there may be a better way to do it that I just don't know of.

echo225: Hi all,

I'm looking for a way to break down a serial input, say the word "Test" for example, then convert that to a binary representation.

Misconception #1. You don't need to convert it to binary. It was binary all along. It had to be converted to text in order for you to see "Test". It would be redundant to convert it to text only to convert back to binary. Just use the binary that you already have stored.

What do you want to do with your laser? What will flashing a binary sequence achieve? It would be safer if you just used an LED.

Example: The letter ‘A’ in ASCII has the value 0x41 or 0b01000001.

If your successively shift this value right by one place and mask off the least-significant bit (or use bitRead) you can isolate all the bits in a character.

echo225:
By get any further I mean I don’t know what to do in order to break these binary outputs down. I tried to create an array in order to save the binary output into slots. But then I just end up with slots of 1101010, 0010110, and so on. But my way of thinking is I would need to break down each 1 and 0 independently in order to be able to output through the laser diode. That’s where I get stuck, and there may be a better way to do it that I just don’t know of.

You need to look through the bitmath section of the reference on this site. There are several ways to get the bits out of a byte.

Here’s one that will take the characcter received over serial and blink an led with the bit pattern with half a second per bit. It is inefficient and blocking, but it does illustrate how to get the bits out.

char c = Serial.read();

for (int i = 0; i < 8; i++){
   
    // if the bit is a 1
    if(c & (1 << i)){
        digitalWrite(somePin, HIGH);
    }
     else {
         digitalWrite(somePin, LOW);
     }
     delay(500);
}

I am using the laser to demonstrate what goes on inside a laser printhead. The rip scans images into ones and zeros and outputs them through a laser onto a photo-reactive drum that pulls charged toner from the cartridge and then onto the paper. It's for a final presentation for a summer internship I have with a printer company. I'm trying to set it up so that during the presentation anyone may input whatever they like into the serial monitor and have the laser output the corresponding values. I will check out bitmath, I'm only concerned how the output would work using a varying length of text rather than one character at a time.

echo225: I'm only concerned how the output would work using a varying length of text rather than one character at a time.

If you want to do a whole string of text, then you will have to deal with it one character at a time.

That isn't quite how laser printers work. At the very least you'll need to convert your text to a bitmap and then output the top row of each letter of your text before moving on the next row, and so on. It gets way more complicated if you use vector fonts...

If you're just using it as a demo and aren't going to print anything, use an LED. I doubt anyone would be impressed if you damaged their eyesight by flashing a laser around the room.

Is readable text written into the serial? Is the laser beam supposed to draw patterns that form readable text? Or just recognisable dots that are ones and zeros, but not graphical font glyphs?

My purposes would simply be a quick demo. Yes a bitmap would provide a more accurate representation if I could sync a motor to it so that the top to bottom pattern of each letter could be drawn but the time it would take to do so would not be worth the short 30 second demo. For using a varying size input, would I need to create an array to store each letter into its own slot, or would the arduino break down each individual letter on its own?

If you don't do bitmap graphics, I don't see the point of the demo - no-one is going to recognise even "Hello world" in plain ASCII.

echo225: My purposes would simply be a quick demo. Yes a bitmap would provide a more accurate representation

It's not a question of "more accurate". Without a bitmap you won't have anything.

The ascii codes for characters don't look like the characters - they are just code numbers.

...R

Here is a snippet from a font definition used by an OLED library.

// standard ASCII 5x8 font (6 pixel spacing including the one-pixel space best added on left side)

#include <avr/pgmspace.h>

const uint8_t font[] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, // space
	0x00, 0x00, 0x5F, 0x00, 0x00, // !
	0x00, 0x07, 0x00, 0x07, 0x00, // "
	0x14, 0x7F, 0x14, 0x7F, 0x14, // #
	0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
	0x23, 0x13, 0x08, 0x64, 0x62, // %
	0x36, 0x49, 0x56, 0x20, 0x50, // &
	0x00, 0x08, 0x07, 0x03, 0x00, // '
	0x00, 0x1C, 0x22, 0x41, 0x00, // (
	0x00, 0x41, 0x22, 0x1C, 0x00, // )
	0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // *
	0x08, 0x08, 0x3E, 0x08, 0x08, // +
	0x00, 0x80, 0x70, 0x30, 0x00, // ,
	0x08, 0x08, 0x08, 0x08, 0x08, // -
	0x00, 0x00, 0x60, 0x60, 0x00, // .

Look at this line.
0x08, 0x08, 0x08, 0x08, 0x08, // -
See how that defines the graphical representation of the dash character?

Where this one
0x00, 0x00, 0x5F, 0x00, 0x00, // !
defines the representation of an exclamation.