Controlling a dc motor with a saved text file, is this possible?

Hello Arduino Community,

I'm curious about whether a project I'm starting is possible and if so, how.

I would like to control a series of vibration motors using text. What I mean is that I would like to save a piece of literature and have my arduino go through every letter of that text, translate it into a value that can then drive my motor at variable speeds.

I'm currently learning to program and am not too far in this endeavour. My teacher is currently very busy with a project so I can't go to them for help at the moment.

With all that I've read and tried to make sense of, my thought is that the text could be somehow saved (in the EEPROM maybe?), and the program code would convert every letter into it's ASCII value and that value would drive the motor at that speed.

For example: "The Cat in the Hat" would be saved. The code would then generate the following values which would drive the motor:

T = 084
h = 104
e = 101
space = 032
C = 067
a = 097
t = 116
space = 032
i = 105
n = 110
space = 032
t = 116
h = 104
e = 101
space = 032
H = 072
a = 097
t = 116

Maybe I'm completely wrong here.

Thanks for the help in advance.

the program code would convert every letter into it's ASCII value and that value would drive the motor at that speed.

your program already has the ASCII values done for you.

char myText[] = "The Cat in the Hat" ;

if you look at

myText[0]
myText[1]
myText[2]

as (byte) not (char) you'll see the ASCII codes

Thanks!

Is there a limit as to how long myText can be?

Also are you saying that I can just copy paste my text right into the code without it needing to be saved elsewhere?

Yes you can - if the text is already known at coding time

you can store your strings if they don't change in program space - Check PROGMEM

here is a bit of code to study

char message1[] = "Text in SRAM, can change: ABCDEFGH";
const char message2[] PROGMEM = "Text in flash memory, locked: ABCDEFGH";

void setup() {
  unsigned int message1Length, message2Length;

  message1Length = strlen(message1);
  message2Length = strlen_P(message2); // The strlen_P() function is similar to strlen(), with a pointer to a string in program space

  Serial.begin(115200);
  Serial.println("Displaying ASCII CHAR");
  Serial.println("****************");
  Serial.print("message1=[");
  for (int i = 0; i < message1Length; i++) Serial.print(message1[i]); // print each char
  Serial.println("]");

  Serial.print("message2=[");
  for (int i = 0; i < message2Length; i++) Serial.print((char) pgm_read_byte_near(message2 + i)); // print each byte as char
  Serial.println("]");


  Serial.println("\n\nDisplaying ASCII CODE");
  Serial.println("****************");
  Serial.print("message1=[");
  for (int i = 0; i < message1Length; i++) {
    Serial.print((byte) message1[i]); // print each char code
    Serial.print(" "); // print a space

  }
  Serial.println("]");

  Serial.print("message2=[");
  for (int i = 0; i < message2Length; i++) {
    Serial.print(pgm_read_byte_near(message2 + i)); // print each byte (as byte)
    Serial.print(" "); // print a space
  }
  Serial.println("]");
}

void loop() {}

There are limits to array sizes to what a 2 byte pointer can index and of course physical memory

You could also write a short PC program (using Python, perhaps) which could read a text file and send the values to the Arduino. This would allow you to use any text file you happen to have on your PC - including very large files that would not fit on an Arduino.

...R

Thanks to the both of you. This makes a bit more sense to me.

I wouldn't be able to use another program because I don't want to have a computer hooked up to the installation.

Ok so the PROGMEM approach is probably what you want to explore if it's a long text.

If it's really very very long then consider adding an SD card with the text file on it. This way you can keep the program the same but change the text by just updating the file on the SD card

It's pretty long, I basically want to "translate" 10 short stories into movement. A motor per story.

What kind of arduino do you have?
And how many characters do you think the stories will have?

Hmmm well some are longer than others.
I've calculated that it's approximately 1,600 characters per page.

The shortest story is 3 pages, so 4,800 characters AND the longest story is about 42 pages so around 76,800 characters.

I'm trying to prototype with an UNO but I can purchase any type and number of Arduinos if required, the payment isn't coming out of my broke pocket thankfully.

If you don't want a connected PC then you need to use an SD Card to store the text files for the Arduino and that means buying an SD Card adapter or shield.

You may want to consider an Arduino Yun which comes with an SD Card socket and can run Python programs on the Linux side.

I don't know anything about the I/O capabilities of a Raspberry Pi but maybe you could do the whole project on one of them?

...R

Hi, I have used a txt file on a handset which runs a CNC router (multiple motors) the software i am using is "Bobcad" which creates a NC file this I upload to a USB stick and plug into the handset a DSP controller I have also use free software called "Mach3" this can also create a txt file which can be run the same way I have added a txt file in order to show you, hope this helps

12mm centre.txt (15.1 KB)

Using a as card on a uno seems the best approach. You can buy shields that add SD capability with other services such as Ethernet or a LCD - advantage is that it plugs right in with a tight fit, or get an SD card and run a few wires. You can create the text files on your PC - ensure its pure ASCII text, save that on the ad card with a simple numbering scheme sur as story0.txt, story1.txt, story2.txt,...strory9.txt and use SD card library to open file for reading, read characters and do your motor things until end of file, then close the file and move to next one