I hope i dont made a question thats been asked here many times if so I could not find a solution for my problem here on the forum yet.
Im trying to coomunicate via Mathlab with my Arduino Mega. I can control Digital Outputs with the examples given by Mathlab.
But when I try to read a Analoge input there goes something slightly wrong.
I connected Pin 13 to to Analoge A0 when I make Pin 13 High I read 4.8V with my multimeter buit Mathlab tells me 5V, it should tell 4.8V. Im sure everyone would think this has to do with Matlab somehting with declarations or usage of variables but thats not the case here.
If I disconnect the wire from Pin 13 to A0 Mathlab tells me a Voltage of 2.345.
Im using the Sketch their demo sketch adio.pde. As shown in the attachment I really hope someone could help me to find out where this goes wrong. I suspect that the analoge input is not being configured well.
Ai ai Im sorry for the mistake in Matlab (no Mathlab verry silly from me) its early your right about that!
Well I powered it up from the USB but my Volkta meter tells 4.8V and this is a calibrated meter and a good one (fluke). So I would expect to read there in my GUI 4.8V. So how is it possible that Matlab tells 5V?
I will experiment with a voltage divider to see if I can get different values.
The analog to digital converter determines the ratio of the voltage being measured to the voltage that the Arduino is running at. If you are measuring the pin voltage at 4.8 V, then the Arduino is running at 4.8 V.
According to by 10 finger calculator, 4.8/4.0 = 1.0. What does your calculator say?
Why would you expect Matlab to see things any different?
PaulS:
The analog to digital converter determines the ratio of the voltage being measured to the voltage that the Arduino is running at. If you are measuring the pin voltage at 4.8 V, then the Arduino is running at 4.8 V.
According to by 10 finger calculator, 4.8/4.0 = 1.0. What does your calculator say?
Why would you expect Matlab to see things any different?
I would expect Matlab tells me 4.8V Im using a readvoltage function. Im sorry maybe I misunderstand it completely.
My calculator and me would tell also that 4.8/4.0 = 1.2 but I think ( as mentioned before) this is a type error
but I think ( as mentioned before) this is a type error
Yes.
Matlab's readvoltage() function is obviously sending messages to the Arduino to tell it to analogRead() a pin. The analogRead() function returns a value from 0 to 1023 to show where on the 0 to ARef voltage the input to the pin to be read is.
If the input is the output from a digital pin, the input IS ARef, so Aref/ARef * 1023 = 1023, which MatLab is ASSuming means 5.0V, since it, apparently, ASSumes the Arduino is running at 5.0V.
This would mean that I could get errors when I want to read out temperatures with Matlab for example? Or I have to use a a good power supply that always has a voltage of 5V, right?