mirror of
				https://github.com/digistump/DigistumpArduino.git
				synced 2025-11-03 13:04:48 -08:00 
			
		
		
		
	added updated tinypinchange and associated libraries to support PRO
This commit is contained in:
		@@ -0,0 +1,64 @@
 | 
			
		||||
/*
 | 
			
		||||
   _____     ____      __    _    ____    _    _   _     _ 
 | 
			
		||||
  |  __ \   / __ \    |  \  | |  / __ \  | |  | | | |   | |
 | 
			
		||||
  | |__| | | /  \_|   | . \ | | / /  \ \ | |  | |  \ \ / /
 | 
			
		||||
  |  _  /  | |   _    | |\ \| | | |__| | | |  | |   \ ' /
 | 
			
		||||
  | | \ \  | \__/ |   | | \ ' | |  __  |  \ \/ /     | |
 | 
			
		||||
  |_|  |_|  \____/    |_|  \__| |_|  |_|   \__/      |_| 2013
 | 
			
		||||
 | 
			
		||||
                http://p.loussouarn.free.fr
 | 
			
		||||
 | 
			
		||||
         ****************************************
 | 
			
		||||
         *   Digispark Debug Demo with 1 I/O    *
 | 
			
		||||
         ****************************************
 | 
			
		||||
 | 
			
		||||
 This sketch demonstrates how to debug a Digispark using a bi-directional serial port using a single I/O.
 | 
			
		||||
 This approach allows to use the built-in Serial Console of the arduino IDE.
 | 
			
		||||
 Please, note this solution requires a native RS232 port (rare today) or a RS232/USB adapter on the development PC.
 | 
			
		||||
 
 | 
			
		||||
 Hardware Wiring:
 | 
			
		||||
 ===============
 | 
			
		||||
                        SERIAL SINGLE I/O
 | 
			
		||||
                         DEBUGGING CABLE
 | 
			
		||||
            ___________________/\__________________
 | 
			
		||||
           /                                       \
 | 
			
		||||
                                              ____
 | 
			
		||||
 .--------.                                  |    \
 | 
			
		||||
 |    GND |--------------------------------+---o5  \
 | 
			
		||||
 |        |                           47K  | |   9o |
 | 
			
		||||
 |        |                        .--###--' | o4   |
 | 
			
		||||
 |  DEBUG |                  4.7K  |         |   8o |
 | 
			
		||||
 |  TX_RX |-------------------###--+--|<|------o3   |    ---> To regular RS232 SubD 9 pins Male of PC
 | 
			
		||||
 |   PIN  |        ^               | 1N4148  |   7o |         or to RS232/USB adapter
 | 
			
		||||
 |        |        |               '-----------o2   |
 | 
			
		||||
 '--------'        |                         |   6o |
 | 
			
		||||
  ATtiny85       Single                      | o1  /
 | 
			
		||||
 (Digispark)      I/O                        |____/
 | 
			
		||||
                                          SubD 9 pins
 | 
			
		||||
                                            Female
 | 
			
		||||
*/
 | 
			
		||||
#include <TinyPinChange.h>
 | 
			
		||||
#include <SoftSerial.h>
 | 
			
		||||
 
 | 
			
		||||
#define DEBUG_TX_RX_PIN         2 //Adjust here your Tx/Rx debug pin
 | 
			
		||||
 
 | 
			
		||||
SoftSerial MyDbgSerial(DEBUG_TX_RX_PIN, DEBUG_TX_RX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driver
 | 
			
		||||
 
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  MyDbgSerial.begin(38400); //After MyDbgSerial.begin(), the serial port is in rxMode by default
 | 
			
		||||
  MyDbgSerial.txMode(); //Before sending a message, switch to txMode
 | 
			
		||||
  MyDbgSerial.println(F("\nDebug enabled"));
 | 
			
		||||
  MyDbgSerial.rxMode(); //switch to rxMode to be ready to receive some commands
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  if(MyDbgSerial.available())
 | 
			
		||||
  {
 | 
			
		||||
    MyDbgSerial.txMode();
 | 
			
		||||
    MyDbgSerial.print(F("\nReceived: "));MyDbgSerial.write(MyDbgSerial.read());MyDbgSerial.print(F("\n"));
 | 
			
		||||
    MyDbgSerial.rxMode();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
  Software serial multiple serial test
 | 
			
		||||
 
 | 
			
		||||
 Receives from the hardware serial, sends to software serial.
 | 
			
		||||
 Receives from software serial, sends to hardware serial.
 | 
			
		||||
 
 | 
			
		||||
 The circuit: 
 | 
			
		||||
 * RX is digital pin 2 (connect to TX of other device)
 | 
			
		||||
 * TX is digital pin 3 (connect to RX of other device)
 | 
			
		||||
 
 | 
			
		||||
 created back in the mists of time
 | 
			
		||||
 modified 9 Apr 2012
 | 
			
		||||
 by Tom Igoe
 | 
			
		||||
 based on Mikal Hart's example
 | 
			
		||||
 
 | 
			
		||||
 This example code is in the public domain.
 | 
			
		||||
 
 | 
			
		||||
 <SoftSerial> adapted from <SoftwareSerial> for <TinyPinChange> library which allows sharing the Pin Change Interrupt Vector.
 | 
			
		||||
 Single difference with <SoftwareSerial>: add #include <TinyPinChange.h>  at the top of your sketch.
 | 
			
		||||
 RC Navy (2012): http://p.loussouarn.free.fr
 | 
			
		||||
 
 | 
			
		||||
 */
 | 
			
		||||
#include <SoftSerial.h>     /* Allows Pin Change Interrupt Vector Sharing */
 | 
			
		||||
#include <TinyPinChange.h>  /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
 | 
			
		||||
SoftSerial mySerial(2, 3); // RX, TX
 | 
			
		||||
 | 
			
		||||
void setup()  
 | 
			
		||||
{
 | 
			
		||||
 // Open serial communications and wait for port to open:
 | 
			
		||||
  Serial.begin(57600);
 | 
			
		||||
   while (!Serial) {
 | 
			
		||||
    ; // wait for serial port to connect. Needed for Leonardo only
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  Serial.println("Goodnight moon!");
 | 
			
		||||
 | 
			
		||||
  // set the data rate for the SoftwareSerial port
 | 
			
		||||
  mySerial.begin(4800);
 | 
			
		||||
  mySerial.println("Hello, world?");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() // run over and over
 | 
			
		||||
{
 | 
			
		||||
  if (mySerial.available())
 | 
			
		||||
    Serial.write(mySerial.read());
 | 
			
		||||
  if (Serial.available())
 | 
			
		||||
    mySerial.write(Serial.read());
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,85 @@
 | 
			
		||||
/*
 | 
			
		||||
  Software serial multple serial test
 | 
			
		||||
 
 | 
			
		||||
 Receives from the two software serial ports, 
 | 
			
		||||
 sends to the hardware serial port. 
 | 
			
		||||
 
 | 
			
		||||
 In order to listen on a software port, you call port.listen(). 
 | 
			
		||||
 When using two software serial ports, you have to switch ports
 | 
			
		||||
 by listen()ing on each one in turn. Pick a logical time to switch
 | 
			
		||||
 ports, like the end of an expected transmission, or when the 
 | 
			
		||||
 buffer is empty. This example switches ports when there is nothing
 | 
			
		||||
 more to read from a port
 | 
			
		||||
 
 | 
			
		||||
 The circuit: 
 | 
			
		||||
 Two devices which communicate serially are needed.
 | 
			
		||||
 * First serial device's TX attached to digital pin 2, RX to pin 3
 | 
			
		||||
 * Second serial device's TX attached to digital pin 4, RX to pin 5
 | 
			
		||||
 
 | 
			
		||||
 created 18 Apr. 2011
 | 
			
		||||
 modified 9 Apr 2012
 | 
			
		||||
 by Tom Igoe
 | 
			
		||||
 based on Mikal Hart's twoPortRXExample
 | 
			
		||||
 
 | 
			
		||||
 This example code is in the public domain.
 | 
			
		||||
 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <SoftSerial.h>
 | 
			
		||||
#include <TinyPinChange.h>  /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
 | 
			
		||||
 | 
			
		||||
// software serial #1: TX = digital pin 2, RX = digital pin 3
 | 
			
		||||
SoftSerial portOne(2, 3);
 | 
			
		||||
 | 
			
		||||
// software serial #2: TX = digital pin 4, RX = digital pin 5
 | 
			
		||||
SoftSerial portTwo(4, 5);
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
 // Open serial communications and wait for port to open:
 | 
			
		||||
  Serial.begin(9600);
 | 
			
		||||
   while (!Serial) {
 | 
			
		||||
    ; // wait for serial port to connect. Needed for Leonardo only
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // Start each software serial port
 | 
			
		||||
  portOne.begin(9600);
 | 
			
		||||
  portTwo.begin(9600);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  // By default, the last intialized port is listening.
 | 
			
		||||
  // when you want to listen on a port, explicitly select it:
 | 
			
		||||
  portOne.listen();
 | 
			
		||||
  Serial.println("Data from port one:");
 | 
			
		||||
  // while there is data coming in, read it
 | 
			
		||||
  // and send to the hardware serial port:
 | 
			
		||||
  while (portOne.available() > 0) {
 | 
			
		||||
    char inByte = portOne.read();
 | 
			
		||||
    Serial.write(inByte);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // blank line to separate data from the two ports:
 | 
			
		||||
  Serial.println();
 | 
			
		||||
 | 
			
		||||
  // Now listen on the second port
 | 
			
		||||
  portTwo.listen();
 | 
			
		||||
  // while there is data coming in, read it
 | 
			
		||||
  // and send to the hardware serial port:
 | 
			
		||||
  Serial.println("Data from port two:");
 | 
			
		||||
  while (portTwo.available() > 0) {
 | 
			
		||||
    char inByte = portTwo.read();
 | 
			
		||||
    Serial.write(inByte);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // blank line to separate data from the two ports:
 | 
			
		||||
  Serial.println();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user