Arduino nano --> Orange Pi with Serial Connection


hi everyone.

i made controller garage door (with aruduino nano) , have connected orange pi serial connection can run openhab.

everything works fine, whole system stops working.
than orangepi can't write arduino , if press fysical button open door (on arduino) won't work either.

what doing wrong? need place capacitor somewhere?
i don't know lot of stuff, capacitor smooths out electricity input can problem.

my arduino code:
code: [select]

/* belangrijk: poort start dicht */

/*
 * busy boolean:
 * als hij bezig is, kan hij geen enkele andere input verwerken. bug voorkomen?
 *
 *
 *433 mhz: connet recever pin 2
 *
 *hc-12
 * rx -> 5
 * tx ->6
 * set ->9
 *
 * time = 38000
 */


#include <rcswitch.h>
#include <softwareserial.h> //for hc-12

int poortvooropen = 8;
int poortvoordicht = 7;
int switch = 4;  //button

int hc12rxdpin = 5;
int hc12txdpin = 6;

string inputstring = "";         // string hold incoming data
boolean stringcomplete = false;  // whether string complete

softwareserial hc12(hc12txdpin,hc12rxdpin); // create software serial port

boolean busy = false;
boolean status = false; // de poort start dicht

rcswitch rec = rcswitch();

void setup() {
  serial.begin(9600);
inputstring.reserve(200); //reserve 200 bytes string
  rec.enablereceive(0); //receiver data on pin 2
 
  pinmode(poortvooropen, output);
  pinmode(poortvoordicht, output);
  pinmode(switch, input);
 
  pinmode(13, output); //for debugging
  digitalwrite(13, low);  //for debugging
 
  serial.println("status:dicht;");

  hc12.begin(9600);                         // open serial port hc12
}

void loop() {
  if(hc12.available()){                     // if arduino's hc12 rx buffer has data
      if(hc12.read() == 49) {
        serial.println("poort activeren - hc12");
        poortswitch();
      } else {
        serial.println("something wrong hc12: " + hc12.read());
      }
    }
 
  if(rec.available()) { //if on 433 up
    if(rec.getreceivedvalue() == 8505745 || rec.getreceivedvalue() == 5592512) {
      serial.println("poort activeren - 433");
      poortswitch();
      rec.resetavailable();
    } else {
      serial.println(rec.getreceivedvalue());
    }
  }
 
  if(digitalread(switch) == high && busy == false ){ //if switch triggered
    poortswitch();
    serial.println("poort activeren - actie door button"); //for debugging
  }

  /* serial */
   if (stringcomplete) {
    if(stringcomplete == "switch") {
      serial.println("poort activeren - serial");
      poortswitch();
    } else {
      serial.println("error: " + stringcomplete);
    }
    inputstring = "";
    stringcomplete = false;
  }

 
}

void poortswitch() {
      busy = true;
  if(status) {
    // poort momenteel open -> poort dicht doen
    poortdicht();
  } else {
    // poort dicht -> poort open doen
    poortopen();
  }
}

void poortopen() { 
  /* aangeven dat de poort open gaat */
  serial.println("status:open-g;");
  digitalwrite(poortvooropen, high);
  digitalwrite(13, high); //for debugging
 
  delay(38000);
 
  digitalwrite(poortvooropen, low);
  digitalwrite(13, low); //for debugging
  serial.println("status:open;");

  /* om bug te voorkomen kan hij maar 1 handeling per keer doen */
  busy = false;
  status = true; // true = poort open
}

void poortdicht() { 
      /* aangeven dat de poort dicht gaat */

  serial.println("status:dicht-g;");
  digitalwrite(poortvoordicht, high);
  digitalwrite(13, high); //for debugging
 
  delay(38000); //kan niet in int gezet worden door bug 38000
 
  digitalwrite(poortvoordicht, low);
  digitalwrite(13, low); //for debugging
  serial.println("status:dicht;");

  /* om bug te voorkomen kan hij maar 1 handeling per keer doen */
  busy = false;

  status = false; //false = dicht.
}

/*
  serialevent occurs whenever new data comes in the
 hardware serial rx.  routine run between each
 time loop() runs, using delay inside loop can delay
 response.  multiple bytes of data may available.
 */
void serialevent() {
  while (serial.available()) {
    // new byte:
    char inchar = (char)serial.read();
    // add inputstring:
    inputstring += inchar;
    // if incoming character newline, set flag
    // main loop can it:
    if (inchar == '\n') {
      stringcomplete = true;
    }
  }
}


the serial.println serial connection orangepi.

my openhab rules:
code: [select]

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "poorttest"
  when
    item poort changed
  then
    var state = poort.state onofftype
    sendcommand (arduino, "poort=" + state + "\n")
end

rule "status" 
 when   
      item arduino received update 
 then 
      var string arduinoupdate = arduino.state.tostring.trim 
 
      if (arduinoupdate == "status:open;") {
status.postupdate("open")
  } else if (arduinoupdate == "status:dicht;") {
status.postupdate("gesloten")
  } else if (arduinoupdate == "status:dicht-g;") {
status.postupdate("dicht aan het gaan")
  } else if (arduinoupdate == "status:open-g;") {
status.postupdate("open aan het gaan")
  } else {
status.postupdate(arduinoupdate)
  }
end 


if system stuck, status "switch". if see system broke , need reboot.


thanks in advance!

simon gulix

first of need post arduino program , diagram showing how connected it.

just wild guess, not idea use string (capital s) class on arduino can cause memory corruption in small memory on arduino. use cstrings - char arrays terminated 0.

if might problem have @ examples in serial input basics - simple reliable ways receive data.

...r


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Arduino nano --> Orange Pi with Serial Connection


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts