Author Topic: External serial device communication  (Read 3098 times)

TheCase

  • Newbie
  • *
  • Posts: 2
External serial device communication
« on: January 25, 2017, 08:09:47 pm »
Is it possible to perform communication to a serial device?

I tried some of the serial samples in the particle IDE but they will not compile.

End of the day, I have a solar water heater controller that uses rs485 to send event data. I was able to accomplish communication over a rs485 device connected to a couple pins on an arduino with SoftwareSerial library. Oak didn't like the code of the SoftwareSerial library.

Is the Oak the right device for such an application?

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: External serial device communication
« Reply #1 on: January 25, 2017, 08:29:14 pm »
Normal Serial.print/println read/write would be directed to pins 3 and 4 on the Oak. (that's RX and TX respectively). You should be able to connect to these with an appropriate serial device. For example, if you want to see serial output from the Oak on a PC based serial monitor you would need an external FTDI Serial to USB (3.3V capable) device connected to these pins. Not sure how and what you want to connect to but the Oak does provide 3.3V RX and TX lines.
« Last Edit: January 25, 2017, 08:32:21 pm by exeng »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: External serial device communication
« Reply #2 on: January 26, 2017, 01:25:42 am »
Yes, as exeng pointed out, it is, and on the pins marked Tx and Rx on the Oak.

Since you said you were trying with Particle Build (and I mostly use the Arduino IDE for the Oak), I just shoved one of the serial example programs into Particle build, and it compiled just fine. As to whether it actually works... have to bear with me for 10 or so minutes... need to dig out a free programmable oak and hook it up to something serial... be back shortly ;)

Code: [Select]
/*
  ASCII table

 Prints out byte values in all possible formats:
 * as raw binary values
 * as ASCII-encoded decimal, hex, octal, and binary values

 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII

 The circuit:  No external hardware needed.

 created 2006
 by Nicholas Zambetti
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 <http://www.zambetti.com>

 */
void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // prints title with ending line break
  Serial.println("ASCII Table ~ Character Map");
}

// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';

void loop() {
  // prints value unaltered, i.e. the raw binary version of the
  // byte. The serial monitor interprets all bytes as
  // ASCII, so 33, the first number,  will show up as '!'
  Serial.write(thisByte);

  Serial.print(", dec: ");
  // prints value as string as an ASCII-encoded decimal (base 10).
  // Decimal is the  default format for Serial.print() and Serial.println(),
  // so no modifier is needed:
  Serial.print(thisByte);
  // But you can declare the modifier for decimal if you want to.
  //this also works if you uncomment it:

  // Serial.print(thisByte, DEC);


  Serial.print(", hex: ");
  // prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);

  Serial.print(", oct: ");
  // prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);

  Serial.print(", bin: ");
  // prints value as string in binary (base 2)
  // also prints ending line break:
  Serial.println(thisByte, BIN);

  // if printed last visible character '~' or 126, stop:
  if (thisByte == 126) {    // you could also use if (thisByte == '~') {
    // This loop loops forever and does nothing
    while (true) {
      continue;
    }
  }
  // go on to the next character
  thisByte++;
}

TheCase

  • Newbie
  • *
  • Posts: 2
Re: External serial device communication
« Reply #3 on: January 26, 2017, 07:31:59 pm »
I was able to get my code to compile under the arduino IDE. 

Still troubleshooting why its not reading data... but at least I'm one step closer

Thank you for the help, both of you.