Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Atmel, PIC, VEX, Fischertechnik

Moderator: Moderatoren

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 20:59

GPS Modul GY-NEO-6M V2

GPS_GY-NEO-6M.JPG
GPS_GY-NEO-6M.JPG (10.98 KiB) 1455 mal betrachtet


Quelle: Ebay

Anschluss-Protokoll: UART
Spannung/Level: 3-5 V kompatibel
Bezugsquelle: u.a. Ebay, z.B. http://www.ebay.de/itm/311296066259
Preis: ca. 12-14 EUR


Treiber-Library:
Serial-lib (standardmäßig in Arduino-Sketch enthalten, standardmäßig bereits eingebunden)
GPS-lib: TinyGPS++ http://arduiniana.org/libraries/tinygpsplus/
https://github.com/mikalhart/TinyGPSPlus
TinyGPSPlus-master.zip
(43.44 KiB) 123-mal heruntergeladen

Anm.: auch für Raspberry Pi geeignet! https://bigdanzblog.wordpress.com/2015/ ... pberry-pi/

Hinweise:
1.) es lassen sich nicht nur geograf. Daten, sondern auch Datum, Uhrzeit, Geschwindigkeit, Kurs und Satellitendaten abfragen
2.) Üblicherweise arbeiten die Sketche für Uno und Nano mit SoftwareSerial():

Code: Alles auswählen

SoftwareSerial ss(4, 3);
void loop()
{
  while (ss.available() > 0)
    gps.encode(ss.read);
    //...

Stattdessen lässt sich aber auch Hardware-Serial verwenden, am besten per UART1 oder UART2 auf Mega oder Due:

Code: Alles auswählen

setup(){
  Serial.begin(115200);  // UART0 für USB-Serial-Terminal Window
  Serial1.begin(9600):   // UART1 für das GPS-Modul
}

void loop()
{
  while (Serial1.available() > 0)
    gps.encode(Serial1.read);
    //...
}

3.) Liste für die verfügbaren Daten:

Code: Alles auswählen

Serial.println(gps.location.lat(), 11); // Latitude in degrees (double)
Serial.println(gps.location.lng(), 11); // Longitude in degrees (double)
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg); // Raw latitude in whole degrees
Serial.println(gps.location.rawLat().billionths);// ... and billionths (u16/u32)
Serial.print(gps.location.rawLng().negative ? "-" : "+");
Serial.println(gps.location.rawLng().deg); // Raw longitude in whole degrees
Serial.println(gps.location.rawLng().billionths);// ... and billionths (u16/u32)

Serial.println(gps.date.value()); // Raw date in DDMMYY format (u32)
Serial.println(gps.date.year()); // Year (2000+) (u16)
Serial.println(gps.date.month()); // Month (1-12) (u8)
Serial.println(gps.date.day()); // Day (1-31) (u8)

Serial.println(gps.time.value()); // Raw time in HHMMSSCC format (u32)
Serial.println(gps.time.hour()); // Hour (0-23) (u8)
Serial.println(gps.time.minute()); // Minute (0-59) (u8)
Serial.println(gps.time.second()); // Second (0-59) (u8)
Serial.println(gps.time.centisecond()); // 100ths of a second (0-99) (u8)

Serial.println(gps.speed.value()); // Raw speed in 100ths of a knot (i32)
Serial.println(gps.speed.knots()); // Speed in knots (double)
Serial.println(gps.speed.mph()); // Speed in miles per hour (double)
Serial.println(gps.speed.mps()); // Speed in meters per second (double)
Serial.println(gps.speed.kmph()); // Speed in kilometers per hour (double)

Serial.println(gps.course.value()); // Raw course in 100ths of a degree (i32)
Serial.println(gps.course.deg()); // Course in degrees (double)

Serial.println(gps.altitude.value()); // Raw altitude in centimeters (i32)
Serial.println(gps.altitude.meters()); // Altitude in meters (double)
Serial.println(gps.altitude.miles()); // Altitude in miles (double)
Serial.println(gps.altitude.kilometers()); // Altitude in kilometers (double)
Serial.println(gps.altitude.feet()); // Altitude in feet (double)

Serial.println(gps.satellites.value()); // Number of satellites in use (u32)

Serial.println(gps.hdop.value()); // Horizontal Dim. of Precision (100ths-i32)



Einfaches Device Example :

Code: Alles auswählen

/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   9600-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
   Alternatively: Serial1 (RX1+TX1, pin 18+19 on Mega/Due)
*/

#include <TinyGPS++.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);

static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;



double frac(double value) {
   return (value - (double)trunc(value) );
}



void setup()
{
  // setup Serial for USB-Monitor
  Serial.begin(115200);
 
  // setup Serial1 for GPS
  Serial1.begin(GPSBaud);
 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);  // init LCD 1602

  Serial.println(F("DeviceExample.ino"));
  Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
  Serial.print(F("Testing TinyGPS++ library v. "));
  Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
}

void loop()
{
  char sbuf[128];
 
  // This sketch displays information every time a new sentence is correctly encoded.
  while (Serial1.available() > 0)
    if (gps.encode(Serial1.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
}



void displayInfo()

  char sbuf[128];
  double   fLatt, fLong, fmin, fdecsec;
  uint16_t decdeg, decmin,
           dday, dmonth, dyear,
           dhour, dmin, dsec, dcsec, nsat;
 
  if (gps.location.isValid())
  {
    fLatt= (double)gps.location.lat();
    fLong= (double)gps.location.lng();
   
    sprintf(sbuf, "Lat:%+012.7f " , fLatt );     
    Serial.print(sbuf);   lcd.setCursor(0, 0);  lcd.print(sbuf);
   
    decdeg = (int)fLatt;
    fmin   = ( fLatt - (float)decdeg) * 60;
    decmin = (int)(fmin);
    fdecsec= (fmin - (float)decmin) * 60 ;
   
    sprintf(sbuf, "B%+04d:%02d'%7.4f ", decdeg, decmin, fdecsec);
    Serial.print(sbuf); lcd.setCursor(0, 0);  lcd.print(sbuf);
   
    sprintf(sbuf, " Lng:%+012.7f ", fLong );
    Serial.print(sbuf);     
   
    decdeg = (int)fLong;
    fmin   = ( fLong - (float)decdeg) * 60;
    decmin = (int)(fmin);
    fdecsec= (fmin - (float)decmin) * 60 ;
   
    sprintf(sbuf, "L%+04d:%02d'%7.4f ", decdeg, decmin, fdecsec);
    Serial.print(sbuf); lcd.setCursor(0, 1);  lcd.print(sbuf);
  }
  else
  {
    Serial.print(F("Location:  INVALID  "));
    lcd.setCursor(0, 1);  lcd.print("Loc.: INVALID");
  }

  if (gps.date.isValid())
  {     
    dday=gps.date.day();
    dmonth=gps.date.month();   
    dyear=gps.date.year();
    sprintf(sbuf, "  Date: %02d/%02d/%04d", dday, dmonth, dyear);
    Serial.print(sbuf);
  }
  else
  {
    Serial.print(F("  Date:  INVALID  "));
  }

  if (gps.time.isValid())
  {
    dhour=gps.time.hour();
    dmin= gps.time.minute();
    dsec= gps.time.second();
    dcsec=gps.time.centisecond();
    nsat =gps.satellites.value();
    sprintf(sbuf, "  Time: %02d:%02d:%02d,%03d Sat.=%02d", dhour, dmin, dsec, dcsec, nsat);
    Serial.print(sbuf);
  }
  else
  {
    Serial.print(F("  Time:  INVALID  "));
  }

  Serial.println();
}

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:04

Platzhalter

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:05

Platzhalter

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:05

PCF8591 : 4x ADC & 1x DAC

Bild

http://tronixstuff.com/2013/06/17/tutorial-arduino-and-pcf8591-adc-dac-ic/

Bild

Code für 4x ADC:

Code: Alles auswählen

// http://tronixstuff.com/tutorials Chapter 52
// John Boxall June 2013

#include "Wire.h"
#define PCF8591 (0x90 >> 1) // I2C bus address
byte value0, value1, value2, value3;

void setup()
{
   Wire.begin();
   Serial.begin(9600);
}

void loop()
{
   Wire.beginTransmission(PCF8591); // wake up PCF8591
   Wire.write(0x04); // control byte - read ADC0 then auto-increment
   Wire.endTransmission(); // end tranmission
   Wire.requestFrom(PCF8591, 5);
   value0=Wire.read();
   value0=Wire.read();
   value1=Wire.read();
   value2=Wire.read();
   value3=Wire.read();
   Serial.print(value0); Serial.print(" ");
   Serial.print(value1); Serial.print(" ");
   Serial.print(value2); Serial.print(" ");
   Serial.print(value3); Serial.print(" ");
   Serial.println();
}


Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:05

Platzhalter

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:06

PCF8574 : 8x IO Multiplexer (read/write)

Bild

http://garagelab.com/profiles/blogs/tutorial-arduino-i-o-port-expander-with-pcf8574

Bild

Arduino Playground:
http://playground.arduino.cc/Main/PCF8574Class

eigener Code zum Lesen von Pinzuständen (Taster lesen): es wird 1 Byte gelesen, darin befinden sich die 8 Pinzustände als Bitmuster.
Alternativ kann auch 1 Byte für 8 Pinzustände geschrieben werden, um damit z.B. 8 LEDs einzeln zu schalten.

Code: Alles auswählen

#include <Wire.h>

#define ADDR_PCF8574  0x30

void setup() {
   Wire.begin();
   writei2cbyte(ADDR_PCF8574, 0xff);
   //...
}

void writei2cbyte(int addr, byte data) {
    Wire.beginTransmission(addr);
    Wire.write(data);
    Wire.endTransmission();
    delay(5);
}




uint8_t readi2cbyte(uint8_t addr) {
  uint8_t  data;

    Wire.beginTransmission(addr);
    Wire.write(1);                     
    Wire.endTransmission();

    Wire.requestFrom(addr, 1);           // Request 1 byte from PCF8574
    while(Wire.available() < 1);         // Wait for byte to become available
    data = Wire.read();                  // then get it!
    return(data);
}


void writei2cBit(uint8_t addr, uint8_t pin, uint8_t value)
{
  uint8_t  data;
 
  data = readi2cbyte( addr );
  if (value == LOW)   
     { data &= ~(1<<pin);  }
  else   
     { data |=  (1<<pin);  }     
  writei2cbyte(addr, data);
}


void loop() {
  //...
  uint8_t bitmask;
 
  bitmask = readi2cbyte(ADDR_PCF8574);  // read all btn states (bitmask) = 1 Byte
  if( bitRead(bitmask,1) ) { }
  else
  if( bitRead(bitmask,2) ) { }
  //...
}

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:07

Platzhalter

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:15

MCP23017 : 16x IO-Multiplexer (read/write)

Bild
Bild

super Tutorial:
http://tronixstuff.com/2011/08/26/tutorial-maximising-your-arduinos-io-ports/

Bild

Code: Alles auswählen

 Example 41.3 - Microchip MCP23017 with Arduino
 http://tronixstuff.wordpress.com/tutorials > chapter 41
 John Boxall | CC by-sa-nc
*/
 
// pins 15~17 to GND, I2C bus address is 0x20
#include "Wire.h"
byte inputs=0;
 
void setup()
{
  Serial.begin(9600);
  Wire.begin(); // wake up I2C bus
 
  Wire.beginTransmission(0x20);
  Wire.write(0x00); // IODIRA register
  Wire.write(0x00); // set all of bank A to outputs
  Wire.endTransmission();
}
 
void loop()
{
  // read the inputs of bank B
  Wire.beginTransmission(0x20);
  Wire.write(0x13);
  Wire.endTransmission();
  Wire.requestFrom(0x20, 1);
  inputs=Wire.read();
 
  // now send the input data to bank A
  Wire.beginTransmission(0x20);
  Wire.write(0x12); // GPIOA
  Wire.write(inputs);    // bank A
  Wire.endTransmission();
  delay(200); // for debounce
}

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 3. Mai 2016 21:16

Platzhalter

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 13. Nov 2016 14:05

I2C Multiplexer / Port Splitter

Bild
https://www.bitwizard.nl/wiki/File:Dsc05850_edit.jpg

Lieferant: z.B. http://bitwizard.nl/shop/I2C-Splitter-Switch-with-PCA9548A-TCA9548A
Lit.: https://www.bitwizard.nl/wiki/I2C_splitter

Below is a sample sketch that will control TWO digital potentionmeters
having the same address, that live on two busses off the i2c splitter
board (BUS1, the second one, and BUS3, the fourth).

It is based on the I2C / "wire" library example that used to control
just ONE of those digital potentiometers.

Instead of

Wire.beginTransmission (addr);

you now have to do:

busBeginTransmission(byte bus,byte addr)

to start communicating with an i2c device on a specific bus. (the chip
allows you to select multiple busses at once, but you don't need that.
On the other hand, with two digital potentiometers at the same
address, you should be able to set them to the same value by selecting
both busses at the same time....busBeginTransmission (BUS1|BUS3, ...) )



Code: Alles auswählen


// I2C Digital Potentiometer
// by Nicholas Zambetti <http://www.zambetti.com>
// and Shawn Bonkowski <http://people.interaction-ivrea.it/s.bonkowski/>

// Demonstrates use of the Wire library
// Controls AD5171 digital potentiometer via I2C/TWI

// Created 31 March 2006

// This example code is in the public domain.

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}


// How are the jumpers set? 0 - 7
#define PCA_JUMPERS 0
#define ADDR_PCA  (0x70+PCA_JUMPERS)


void selectBus (byte bus)
{
  Wire.beginTransmission(44); // transmit to device #44 (0x2c)
  Wire.write(bus);            // sends control register byte 
  Wire.endTransmission();     // stop transmitting
}


// Use these values to select a bus. You COULD enable multiple
// busses at the same time, but normally that is not necessary.
#define BUS0 0x01
#define BUS1 0x02
#define BUS2 0x04
#define BUS3 0x08
#define BUS4 0x10
#define BUS5 0x20
#define BUS6 0x40
#define BUS7 0x80



void busBeginTransmission(byte bus,byte addr)
{
  selectBus (bus);
  Wire.beginTransmission (addr);
}


void busEndTransmission(void)
{
  Wire.endTransmission();     // stop transmitting
}


void busRequestFrom(byte bus,byte addr, byte num)
{
  selectBus (bus);
  Wire.requestFrom (addr, num);
}


byte val = 0;

void loop()
{

  busBeginTransmission(BUS1, 44); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet
  Wire.write(byte(0x00));            // sends instruction byte 
  Wire.write(val);             // sends potentiometer value byte 
  busEndTransmission();     // stop transmitting

  busBeginTransmission(BUS3, 44); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet
  Wire.write(byte(0x00));            // sends instruction byte 
  Wire.write(63 - val);             // sends potentiometer value byte 
  busEndTransmission();     // stop transmitting


  val++;        // increment value
  if(val == 64) // if reached 64th position (max)
  {
    val = 0;    // start over from lowest value
  }
  delay(500);
}


Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E

Benutzeravatar
HaWe
Administrator
Administrator
Beiträge: 5385
Registriert: 11. Jan 2006 21:01
Wohnort: ein kleiner Planet in der Nähe von Beteigeuze

Re: Arduino Driver libraries (Baustelle): Displays, SD, I2C, UART,...

Beitragvon HaWe » 13. Nov 2016 14:05

Platzhalter
Gruß,
HaWe
±·≠≈²³αβγδε∂ζλμνπξφωΔΦ≡ΠΣΨΩ∫√∀∃∈∉∧∨¬⊂⊄∩∪∅∞®
NXT NXC SCHACHROBOTER: https://www.youtube.com/watch?v=Cv-yzuebC7E


Zurück zu „allgemeine / Nicht-Lego-Robotik und Elektronik“

Wer ist online?

Mitglieder in diesem Forum: Yahoo [Bot] und 11 Gäste

Lego Mindstorms EV3, NXT und RCX Forum : Haftungsauschluss