Converting a CSV file to Arduino code

Status
Not open for further replies.

Thread Starter

s200bym

Joined Aug 9, 2017
76
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.
 

Attachments

spinnaker

Joined Oct 29, 2009
7,835
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,
 

AlbertHall

Joined Jun 4, 2014
9,873
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.
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.
 

tranzz4md

Joined Apr 10, 2015
310
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.
 

MrSoftware

Joined Oct 29, 2013
1,780
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/tutorials/mcp4725-digital-to-analog-converter-hookup-guide?_ga=2.264688527.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-Reader-interface-driver-Arduino/dp/B01MSNX0TW/ref=asc_df_B01MSNX0TW/?tag=hyprod-20&linkCode=df0&hvadid=167141218295&hvpos=1o1&hvnetw=g&hvrand=7339596104824634559&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=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..
 
Status
Not open for further replies.
Top