[Coco] Coco -> Arduino -> Drivewire and back again... the arduino code... for connecting via the serial

Chris Ahrendt chrisahrendt at bellsouth.net
Fri Jun 20 00:09:54 EDT 2014


Ok got the code done...

#include <SPI.h>
#include <Ethernet.h>

// The network port on which to listen for incoming connections.
int network_port = 5331;

// The baud rate to use for serial communication.  This needs to match the
// speed used by the microcontroller (e.g. the value passed to
// Serial.begin() in an Arduino sketch).
// The communication protocol shall follow the RS-232 standard of 8-N-1
// (1 start bit, 8 data bits, and 1 stop bit).
// By default the Arduino uses 8n1 so we dont have to set anything but 
the baud rate
// For the Color Computer 2, the supported clock
// speed shall is .89MHz and the bit rate is 57,600 bits per second. For the
// Tandy Color Computer 3, the supported clock speed is 1.78MHz and the bit
// rate is 115,200 bits per second
// int serial_baud_rate = 115,200; for the coco 3
int serial_baud_rate = 57600;

byte OP_INIT = 0x49;
byte OP_TERM = 0x54;
byte OP_RESET1 = 0xFE;
byte OP_RESET2 = 0xFF;
byte OP_NOP = 0x00;

// Whether or not to print data coming from the serial port in Processing.
boolean print_in_processing = true;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress svr1(1,1,1,1);

EthernetClient client;

void setup()
{
   // start the Ethernet connection:
   Ethernet.begin(mac);

   Serial.begin(serial_baud_rate);
   while (!Serial) {
     ; // wait for serial port to connect
   }
   establishContact();  // send a byte to establish contact until 
receiver responds
   client.connect(svr1, network_port);
}

void loop()
{

   // as long as there are bytes in the serial queue,
   // read them and send them out the socket if it's open:
   while (Serial.available() > 0) {
     char inChar = Serial.read();
     if (client.connected()) {
       client.print(inChar);
     }
   }

   // if there are incoming bytes available
   // from the server, read them and print them:
   if (client.available()) {
     char c = client.read();
     Serial.print(c);
   }

   // if the server's disconnected, stop the client:
   if (!client.connected()) {
     Serial.println((char)OP_TERM);
   }
}

void establishContact() {
   while (Serial.available() <= 0) {
     Serial.print((char)OP_NOP);   // send a OP_NOP
     delay(300);
   }
}


Now to wait for the ethernet shield and try to figure out how to see if 
the drivewire server has a port and listens on it for connections... 
anyone help there?

So can someone help me with the cartridge connection so it can go faster...


Chris


More information about the Coco mailing list