Go Down

Topic: Controlling Automower (Read 41307 times) previous topic - next topic

Dawiinci

I have an Automower 220 AC which I want to control with the Arduino Yun. There are people who have done this already with other system and it works.

However once I connect the Yun to the Automower it doesn't work. I'm not sure if I messed up the connection or the sketch. Except the temperature and humidity I don't get any feedback. So I assume there is something wrong with the serial connection. (maybe in doCommand)

Attached you'll find my sketch, and some information about the connection.

I have the information from here:
http://homematic-forum.de/forum/viewtopic.php?t=7295

Thanks for any help in advance!

Dawiinci

Can someone please confirm if the serial code should work?

Thanks

pylon

Don't you think you should start with an easier sketch? One that just does the serial communication with your mower?

The Serial object is the virtual serial interface on the USB bus. If you want to use the hardware serial interface on pin 0 and 1, use the Serial1 object.

Dawiinci

Thanks for your help I really appreciate it!

The problem is I need to have it connected via Wifi since a cable connection is not possible. But I have some experience with the modified bridge sketch in another project which works pretty well.

In short words I can't send any "serial" code without the bridge sketch. As far as I understand I can't use USB and Pin0/Pin1 anyway.

Since the Automower has no advanced protocol I have just to send the HEX code and listen to the answer. In theory pretty simple.

1 Get command to do something
2 Send HEX code through TTL
3 wait and listen to answer on TTL
4 store HEX code to send it back to the request over HTTP

Problem seems to be in step 2 and 3.

pylon

Quote
In short words I can't send any "serial" code without the bridge sketch. As far as I understand I can't use USB and Pin0/Pin1 anyway.


I understand that in the final application you have to use the WiFi for the communication. But I would try to communicate with the mower over simple serial communication first and when this works advance to the WiFi connection.

Why can't you use USB? You cannot use the hardware serial interface and the Bridge class at the same time, that's correct.

To be prepared for the WiFi usage later, you can start using the AltSoftSerial library (https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html) to get a software emulation of a serial interface and one that is not blocking the complete Arduino. The pins are fixed to 13 and 5. You'll loose your LED but you can use any other pin to light an LED.

Dawiinci

I did the other way - the bridge (Wifi and HTTP) works but the serial connection doesn't. The problem is I can't really take the robot inside to test this and I don't want to take the computer outside.

Maybe I don't understand some restrictions from the bridge sketch and serial over Pin1/Pin0:
Quote
... You cannot use the hardware serial interface and the Bridge class at the same time, that's correct.

pylon

Quote
Maybe I don't understand some restrictions from the bridge sketch and serial over Pin1/Pin0:


The hardware serial interface is used to communicate between the two processors the Yun has, on the AVR-side (the Arduino sketch) the Bridge class is responsible for this.

How did you connect the mower to the Arduino? Please don't post the same pictures again, I want to see how you did it.

Dawiinci

OK, here are some pictures (front, back and connector to Automower) including a short description.

470 uF 35 V capacitor
Spark Fun Logic Level Converter
serial (HV) connected to 1 and 0 on the Arduino
power connected to 5V  and GND
don't mind the blue sensor brick

Thanks!

pylon

Quote
serial (HV) connected to 1 and 0 on the Arduino


This probably won't work because the hardware serial interface (which is on pin 0 and 1) is used for inter-processor communication on the Yun. If you have pins 5 and 13 in the Yun unconnected, use the AltSoftSerial library (https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html) to get a software emulated serial interface.

Quote
power connected to 5V  and GND


Your schematics say 3V3 and not 5V for the mower.

How do the wires connect to the mower?

Dawiinci

Automower powers the Yun with 5V and also delivers 3.3V for serial.

I will have a look at the library. Thanks.

Dawiinci

#10
May 12, 2014, 07:41 pm Last Edit: May 12, 2014, 07:44 pm by Dawiinci Reason: 1
I replaced the hardware serial part in my sketch with SoftwareSerial:

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 7); // RX, TX


replaced in void setup()
Code: [Select]
  Serial.begin(9600);
with
Code: [Select]
  mySerial.begin(9600);


and added in void loop()
Code: [Select]
 if (mySerial.available())
   Serial.write(mySerial.read());
 if (Serial.available())
   mySerial.write(Serial.read());


and of course changed the communication
Code: [Select]
// Send
mySerial.write(commandAutomower, 5);

// Receive
delay (1000);
if (mySerial.available() >= 5)
{
  mySerial.readBytes(statusAutomower, 5);
}


However I'm not sure if I should replace    
Code: [Select]
mySerial.readBytes(statusAutomower, 5);
with
Code: [Select]
mySerial.read(statusAutomower, 5);


I couldn't test it yet but are there any concerns  about these changes?



pylon

Code: [Select]
mySerial.read(statusAutomower, 5);

There is no read() method that takes two arguments. This won't work.

Why don't you use AltSoftSerial but SoftwareSerial? The later will make you much more trouble because it blocks interrupts during every transfer and consumes all processing power available. So you might have to slow down the controlling application on the PC to not overflow the incoming serial hardware doing the Bridge transfer. The SoftwareSerial will block interrupts for at least 1ms (1 byte) during which the Bridge interface might transfer up to 25 bytes, 24 of them might magically disappear because no interrupt handler is emptying the hardware register.

Dawiinci

Makes sense to use AltSoftSerial you are right.

I receive 5 bytes and I assumed it will put it into the array of the size 5.
But I have to go through this code again.

Dawiinci

#13
May 13, 2014, 07:37 pm Last Edit: May 13, 2014, 07:51 pm by Dawiinci Reason: 1
Ok, I changed it to AltSoftSerial. First I thought it would be better to use something that is already included.

Code: [Select]
#include <AltSoftSerial.h>
AltSoftSerial altSerial;


Code: [Select]
void setup() {
...
  altSerial.begin(9600);
}

/
Code: [Select]
/ Send
altSerial.write(commandAutomower);

// Receive
delay (1000);
if (altSerial.available() >= 5)
{
  altSerial.read(statusAutomower);
}


I'm not sure about the following:
1) Pin5 and Pin13 apply for the Yun as well? In that case I can't use the internal LED anymore?
2) commandAutomower is an array with 5 bytes (HEX). Will altSerial.write(commandAutomower, 5); send out these 5 bytes in order without any LF CR or something like this? Does write even work?
3) Will altSerial.read(statusAutomower); read only the next 5 bytes? What happens if there are only four or six?
4) If I wait 1000 ms before reading (to give the Automower time to respond), will it be buffered or is it better not to wait?

Thanks again!



edit:
I get this error message
Quote
Automower.ino: In function 'void doCommand(YunClient)':
Automower:157: error: no matching function for call to 'AltSoftSerial::read(uint8_t [5])'
/Arduino/libraries/AltSoftSerial/AltSoftSerial.h:44: note: candidates are: virtual int AltSoftSerial::read()

pylon

Code: [Select]
Automower.ino: In function 'void doCommand(YunClient)':
Automower:157: error: no matching function for call to 'AltSoftSerial::read(uint8_t [5])'
/Arduino/libraries/AltSoftSerial/AltSoftSerial.h:44: note: candidates are: virtual int AltSoftSerial::read()


Use your old readBytes method, as I already wrote, there is no read method that reads multiple bytes.

Quote
1) Pin5 and Pin13 apply for the Yun as well? In that case I can't use the internal LED anymore?


Yes.

Quote
2) commandAutomower is an array with 5 bytes (HEX). Will altSerial.write(commandAutomower, 5); send out these 5 bytes in order without any LF CR or something like this? Does write even work?


It will send these 5 bytes (bytes are not in hex although they may be printed in hex) over the emulated serial interface. Yes, write works.

Quote
3) Will altSerial.read(statusAutomower); read only the next 5 bytes? What happens if there are only four or six?


It will do nothing except generating a compiler error. See above.

Quote
4) If I wait 1000 ms before reading (to give the Automower time to respond), will it be buffered or is it better not to wait?


If wait means you're calling delay() it's always better not to do that if anything else should happen on your Arduino (as receiving characters from any interface). Although most of this stuff is handled in the background using interrupts, these handlers just copy the incoming stuff to buffers and these buffers may overrun. Try to always react on events and never wait for fixed times except you have no other option.

Go Up