0

I am trying to command my Arduino Uno from a Java program using ardulink

The function in Arduino is the following (using the Servo class):

#define Init(port) \
    attach(port); \
    pinMode(A3,OUTPUT); \
    digitalWrite(A3, HIGH);

and in my JAVA program is

Link link = Link.getDefaultInstance();
boolean connected = link.connect("COM6", 57600);

//send messages
MessageInfo msg=link.sendPowerPinSwitch(9, IProtocol.POWER_HIGH);

However I don't know the equivalence of A3 in pin numbers to be able to call "sendPowerPinSwitch" I tried with "9" cause I found in the documentation file the following:

#define CON1_DIG    9

and the CON1_DIG is the one associated to the barrier in this doc:

http://moway-robot.com/wp-content/files_mf/teachers_guide_moway_smart_city.pdf

But it did not work :(

How can I find the appropriate pin number for "A3" ?

Alain O'Dea
  • 21,033
  • 1
  • 58
  • 84
sabrina2020
  • 2,102
  • 3
  • 25
  • 54

1 Answers1

1

The pins A0 to A5 on an Arduino Uno are actually numbered 14 to 19, the A-stuff are simply names. I used this simple enum to do this conversion for me:

public enum Pin
{
    A0, A1, A2, A3, A4, A5;

    public int toNumber()
    {
        return ordinal() + 14;
    }
}

Your can use this enum like this:

MessageInfo msg = link.sendPowerPinSwitch(Pin.A3.toNumber(), IProtocol.POWER_HIGH);

I think that wont work though, since the A-pins aren't digital pins and that method looks like it sets the digital output. Is there maybe a analog pin method in the library you're using?

Todd Sewell
  • 1,444
  • 12
  • 26
  • @sabrina2020 did this answer work for you? If so you should accept it. – Alain O'Dea Nov 12 '15 at 18:55
  • I tried it but I dont know if it is working or not cause I got the following exception `Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: 1024 at org.zu.ardulink.connection.serial.AbstractSerialConnection$SerialReader.run(AbstractSerialConnection.java:224) at java.lang.Thread.run(Unknown Source)` that I still don't know its cause, may be something else is causing it. – sabrina2020 Nov 13 '15 at 07:58
  • @sabrina2020 see my edit for an answer to your question – Todd Sewell Nov 13 '15 at 19:02
  • @ToddSewell Actually I tried both sendPowerPinSwitch and sendPowerPinIntensity but with no success, I started another thread for this problem: http://stackoverflow.com/questions/33688838/command-arduino-uno-using-ardulink . Thanks! – sabrina2020 Nov 16 '15 at 10:10