i was wondering if someone out there can help me with a code I am trying to write...or should I say get started?
What I need to accomplish is to output a voltage in analog value (255) that represents a number, or a string of numbers like 123456 I have already accomplished this somewhat. The somewhat is: I can output the value I need using single digits ex: dac.output(55.08); 55.08 being the value that represents a single number like the 1 in 123456. What I would like to do is set up a sketch that allows my 6 digit numbers to be referenced against the digits 0 thru 9 that represent a known value: Ex
my numbers would be 6 digits long but have to be output singularly 1 (55.08) delay (pull up to 255) 2 (60.00) delay( pull up to 255) 3 (65.00) delay (pull up to 255)etc......
my numbers would look like this for example.
110705
110708
110776
110780
110782
110788
110789
110802
110864
110878 etc....
So to sum up I need a code or to be put in the right direction on how to tell arduino (SPI) to output the known voltage by referencing my 6 digit numbers using the known 255 value... I have 5000 6digit numbers. Any help would be greatly appreciated.
What I need to accomplish is to output a voltage in analog value (255) that represents a number, or a string of numbers like 123456
I'm sorry, but this makes no sense at all. You say you need to output a voltage in value. What does that mean?
Are you reading this voltage from somewhere? How does that represent a number? How does that represent a string of numbers?
0= 30.00 (converted voltage) 255= 5vdc
How is the 30 converted? Is it converted somehow to 255? How does that equal 5V when the range of values from an analog pin is 0 to 1023 (which represents 5V)?
That table is nowhere near linear, and is not even in increasing or decreasing order. How was it arrived at?
how to tell arduino (SPI) to output the known voltage by referencing my 6 digit numbers using the known 255 value.
Again, this doesn't make sense. You can split the 6 digit number into 6 separate digits, and use the digit as the index into an array, to get the value. The relationship between the value and the digit makes no sense to me, but I guess that doesn't really matter.
I have 5000 6digit numbers.
What do they represent? Where are you storing them?
Thank you for your reply....The numbers I gave are not real conversions, I just put them in there as an example. I am doing a project on outputting different voltages using a DAC and converting them with ADC. Like I stated it's easy enough to do it if I only want to do a few 6 digit numbers, but I want to see how much I can actually output and read on serial monitor. I have generated 5000 6 digit numerical combinations and I want to run them through and actually see if I can get a stable out put. I have already written a sketch to start from 000000-999999 but that's not what I am after here (it is chronological), I want to put in my 5000 random numbers into the sketch and see if Arduino can follow. I really hope that this is not too confusing, I am a beginner and I'm learning. The below sketch is using 654321 as my random number. Again I would like to put in my list of 5000 random 6 digit numbers and have Arduino run through them and output it as a voltage. I write in the sketch, 1 is this value, 2 is this value, 3 is this value.....etc and when I run the sketch whenever 1 is seen it automatically outputs that value stated, and for 2, 3, 4, 5, 6, 7, 8, 9, 0 (it's specific value also )
here is the sketch I am working with
#include <SPI.h>
#include <DAC_MCP49x1.h>
// The Arduino pin used (SPI out) for the slave select / chip select (pin 2 on DAC)
#define SS_PIN 10
// Set up the DAC.
// First argument: model MCP4901
// Second argument: SS pin (10 is preferred)
// (The third argument, the LDAC pin, can be left out if not used)
DAC_MCP49x1 dac(DAC_MCP49x1::MCP4901, SS_PIN);
void setup() {
// Set the SPI frequency to 16 MHz (Arduinos) DIV2 = 8 MHz
dac.setSPIDivider(SPI_CLOCK_DIV8);
// Use "port writes", see the manual page. In short, if you use pin 10 for
// SS (and pin 7 for LDAC, if used)
dac.setPortWrite(true);
}
void loop() {
dac.output(255);
delay(500);
dac.output(117.86); //6
delay(500);
dac.output(255);
delay(500);
dac.output(106.53); //5
delay(500);
dac.output(255);
delay(500);
dac.output(92.93); //4
delay(500);
dac.output(255);
delay(500);
dac.output(83.86); //3
delay(500);
dac.output(255);
delay(500);
dac.output(72.53); //2
delay(500);
dac.output(255);
delay(500);
dac.output(61.20); //1
delay(500);
dac.output(255);
delay(500);
}
Moderator edit: </mark> <mark>[code]</mark> <mark>
bent:
I am doing a project on outputting different voltages using a DAC and converting them with ADC.
It sounds as if you are trying to create a serial encoding system where the sending side sends a digit by outputting one of ten discrete analog values, and the receiving side reads the analog value and determines which of the ten possible digits it represented. Do this six times, and in theory you have transferred a six-digit number.
This is a rather peculiar encoding scheme and I can't imagine any real-world situations where it would be useful, but I don't see anything fundamentally impossible about it. I can see a couple of problems you will need to address to get it working, though. It will rely on the sender and receiver agreeing when the output of each digit starts and ends. In conventional serial encoding schemes this is indicated by start and stop bits and having both sides agree on a known baud rate. You don't seem to have anything like that here, so I would expect that the sending and receiving side would eventually get out of sync and confused about when each digit started and ended. I suppose you could address that by implementing the sender and receiver in the same sketch so that the receiver can know implicitly when each digit starts and ends, but the resulting communication mechanism would be extraordinarily pointless. Another way to address this would be to use a synchronous transmission by sending a second output which indicated when each digit started and ended - for example, a square wave which changed state each time a digit was sent.
The second problem is that you're sending a sequence of six-digits values but haven't provided any way to indicate where each set of six ends; all you have is a digit stream. As a prototype you might pretend that the stream is perfectly reliable and just assume that every six received digits constitutes a complete message. In the real world you would need to deal with added/dropped/corrupted digits and would need to provide a way to detect them - for example, by introducing a known delay between each message or adding a terminating value.
Thanks all for the great replies...I love learning!! is there someone that could post examples of the code i would need to write, I am unfamiliar with arrays, yes I have read what they stand for but I still have no clue on how to implement what I need to do in my sketch. If someone could please start me off with example code that would be great. I love the fact that people are willing to post replies!!
Is there any point to doing this, or are you just doing it as a learning project? Supposing it's a project that has some purpose, what is the reason for using this analog encoding scheme rather than any of the commonly available communication mechanisms? The reason I'm asking is that you seem to have come up with an extraordinarily contrived encoding scheme, and now you're asking somebody to implement it for you. It's not obvious to me that it's worth spending your time on it, let alone somebody else's.