From Thursday, May 23rd (05:00 PM CDT) through Friday, April 24th (1:30 AM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Full Analog Input Support for Arduino MEGA Boards

Hi there,

when using a Arduino Mega with the LabView toolkit, I figured that it is not possible to use all analog input pins on the Mega. Looking at the LIFA Firmware this seems to be no mistake as the code only supports 6 analog Inuts as can be seen in the following code:

// Reads all 6 analog input ports, builds 8 byte packet, send via RS232.

void analogReadPort()

{

  // Read Each Analog Pin

  int pin0 = analogRead(0);

  int pin1 = analogRead(1);

  int pin2 = analogRead(2);

  int pin3 = analogRead(3);

  int pin4 = analogRead(4);

  int pin5 = analogRead(5);

  //Build 8-Byte Packet From 60 Bits of Data Read

  char output0 = (pin0 & 0xFF);  

  char output1 = ( ((pin1 << 2) & 0xFC) | ( (pin0 >> 8) & 0x03) );

  char output2 = ( ((pin2 << 4) & 0xF0) | ( (pin1 >> 6) & 0x0F) );

  char output3 = ( ((pin3 << 6) & 0xC0) | ( (pin2 >> 4) & 0x3F) );   

  char output4 = ( (pin3 >> 2) & 0xFF);   

  char output5 = (pin4 & 0xFF);

  char output6 = ( ((pin5 << 2) & 0xFC) | ( (pin4 >> 8) & 0x03) );

  char output7 = ( (pin5 >> 6) & 0x0F );

  // Write Bytes To Serial Port

  Serial.print(output0);

  Serial.print(output1);

  Serial.print(output2);

  Serial.print(output3);

  Serial.print(output4);

  Serial.print(output5);

  Serial.print(output6);

  Serial.print(output7);

}

Does anyone know how to extend this piece of code to utilize all analog input Pins on a Arduino Mega?

Any help is appreciated.

Best regards,

Jan

0 Kudos
Message 1 of 2
(3,143 Views)

According to this thread

<https://decibel.ni.com/content/message/32559#32559>

the example for the Mega has been fixed so it can read analog channels 0 to 14.  If you need to read analog channel 15 you will need to modiffy the ":Check for Pin out of Range" sub VI.  You need to set "Num Pins" to 16 instead of 15.

hrh1818

0 Kudos
Message 2 of 2
(2,525 Views)