- "Specified key type does not match the type expected for this container." This error usually occurs when you're trying to access an element in a container (like a Dictionary or Map) using a key of an incorrect type. In this case, it could be that the 'A0' you're using to specify the analog pin might not be correct.
- "The first input must contain a multiple of 2 elements to convert from uint8 (8 bits) to uint16 (16 bits)." It's saying that some function is trying to convert an 8-bit unsigned integer (uint8) to a 16-bit unsigned integer (uint16), but the input isn't compatible.
Arduino readVoltage not working
조회 수: 21 (최근 30일)
I'm trying to read the voltage from an analog pin on an arduino leonardo for a university project. Currently I'm just working in the MATLAB command window and i type a = arduino() which works but when I type readVoltage(a, 'A0') I get one of two errors. Usually I get "Specified key type does not match the type expected for this container." but sometimes I get "The first input must contain a multiple of 2 elements to convert from uint8 (8 bits) to uint16 (16 bits).". I'm copying exactly what i see online word for word so why isnt it working?
Aman Banthia 2023년 10월 25일
I understand you are trying to read the voltage from an analog pin (A0) on an Arduino Leonardo using MATLAB. You're creating an Arduino object in MATLAB using the command ‘a = arduino()’, which is working fine. However, when you're trying to read the voltage using the command ‘readVoltage(a, 'A0')’, you're encountering two different errors.
Without more information about your setup, it's hard to diagnose exactly what's going wrong. However, here are some steps you could try:
Check your Arduino board type: Make sure that you're specifying the correct board type when you create the Arduino object in MATLAB. For an Arduino Leonardo, it should be:
a = arduino('COM port', 'Leonardo');
Replace 'COM port' with the actual COM port your Arduino is connected to. You can find this in the Arduino IDE under 'Tools' -> 'Port'.
Check your pin specification: Make sure you're specifying the pin correctly. For analog pin A0, it should be:
voltage = readVoltage(a, 'A0');
If the above steps don't solve your problem, it could be an issue with the MATLAB support package for Arduino itself or the communication between MATLAB and your Arduino board. In this case, you might want to try reinstalling the support package, or testing your Arduino board with a simple sketch in the Arduino IDE to make sure it's working correctly.
Please refer to the following MATLAB documentation link to know more about the MATLAB Support Package for Arduino Hardware:
Hope the above answer helps.
MathWorks MATLAB Hardware Team 2023년 10월 26일
Thank you for contacting us. We apologize for the inconvenience you are experiencing.
To resolve this issue, we kindly request that you reach out to our technical support team. They will be able to provide you with the necessary assistance.
MATLAB Hardware Team