Converting a CSV file to Arduino code

Discussion in 'Programmer's Corner' started by s200bym, Dec 29, 2018.

Thread Status:
Not open for further replies.
  1. s200bym

    Thread Starter Member

    Aug 9, 2017
    65
    2
    Hi All,

    Is it possible to convert a CSV file into code? I am trying to replicate a signal from another microcontroller and output the same signal from the Arduino.

    Please find attached the CSV file.

    Mike.
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    7,815
    3,665
    You are providing a file that looks like the output of a scope not code. So your answer.is no. The Arduino is not magic. It is just a computer capable of outputting either a 0 or 5V out (I do not thing it has analog out but if it did it would be 0-5V). And it needs to be programmed to do all of that.

    Not only will you need to write the code, you are going to have to design a circuit that is capable of producing negative voltages from what looks like -0.2 to -0,312 volts,
     
  3. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,592
    1,848
    No, I'm afraid it is not that simple. You are going to have to note how many samples the signal is high, then how many low and so on to the end of the signal. Each sample is 0.5uS so when you know how many samples the signal was low/high you can calculate how long it was in that state. Then all (;):eek:) you have to do is to write the code that will output a signal to match those timings.
     
  4. tranzz4md

    Member

    Apr 10, 2015
    314
    79
    YOU can write the code for the Arduino to produce an output based on an input. You can use an output from your other controller to drive that Arduino input.

    You can (and most likely will) use another "controller" (your PC) to produce your Arduino program code, and must use one to load it into the Arduino. That being the case, you could program a controller to "automatically" produce code based on input -other than your keyboard entry-level which would then be loaded into an Arduino and executed. It seems you realize that, and want to do it.

    The action of the Arduinos outputs are of course determined by the code that the CPU chip is executing, but we generally use the inputs as the primary means of determining the action of the outputs. If you need to entirely electrically isolate the Arduino from the other controller, optic isolation circuits can be used.
     
  5. s200bym

    Thread Starter Member

    Aug 9, 2017
    65
    2
  6. MrSoftware

    Senior Member

    Oct 29, 2013
    1,369
    426
    Yes, kinda sorta, assuming the limitations of the Arduino are OK for your case. The Arduino has analog output features on a few pins (depending on which Arduino you're using), but what it actually gives you is a PWM output and the analog value that you write to the pin changes the duty cycle. While you could add more components to filter this into an analog signal, there would be limitations and I do not recommend doing it this way.

    Instead use an external DAC. Write a script to convert your CSV file to a C array (assuming the Arduino has enough memory for all of your data), then write your Arduino code to parse the array and send the values to an external DAC. Now you will get real analog output to match your values. Here is an example device with a HowTo:

    https://learn.sparkfun.com/tutorial...7.1212081735.1546110003-1355176832.1536320139

    If your data is too big to fit into the Arduino memory, then you can instead put the data on an SD card, then use the Arduino to read the data from the SD card and send the values to the DAC. Here is an example SD card reader for Arduino:

    https://www.amazon.com/Adapter-Read...ocphy=9052625&hvtargid=pla-305154590559&psc=1

    I haven't used either of these myself, but check around and there are likely Arduino libraries that will help you communicate with them. Also draw out the Arduino and these modules on paper, and draw lines connecting the proper pins to each device. Sometimes only specific pins work for specific things, for example an Arduino UNO only has SPI hardware support on pins 11, 12 and 13. So by drawing it out, you can be sure that the necessary pins aren't already being used for something else, etc..
     
  7. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    7,592
    1,848
    It has been established, in the other thread, that the data is asynchronous serial and TS has set up the Arduino serial to send the message in the CSV file and it works. QED.
     
    MrSoftware and ericgibbs like this.
  8. MrChips

    Moderator

    Oct 2, 2009
    18,463
    5,856
    s200bym likes this.
Loading...
Thread Status:
Not open for further replies.