Modifications
Sauter à la navigation
Sauter à la recherche
← Modification précédente
Modification suivante →
RPI-ShieldBridge-I2C
(voir la source)
Version du 22 janvier 2014 à 07:53
1 178 octets ajoutés
,
22 janvier 2014 à 07:53
aucun résumé de modification
Ligne 2 :
Ligne 2 :
{{traduction}}
{{traduction}}
+
== Introduction ==
+
A small guide to show the communication via I2C between the Arduino (RPi-ShieldBridge) and Raspberry Pi.
+
+
The I2C pins of the Raspberry Pi are connected to the AVR and the Arduino Shield connectors (SDA+SCL) on the RPi-ShieldBridge.
+
+
== Préparer ==
+
+
Téléversez le sketch/croquis suivant sur votre RPi-ShieldBridge.
+
+
<nowiki>#include <Wire.h>
+
+
#define ADDRESS 0x30
+
+
void setup()
+
{
+
pinMode(13, OUTPUT); // set pin 13 as output (LED connected)
+
digitalWrite(13, LOW); // set pin 13 to low (0V)
+
+
Wire.begin(ADDRESS); // join I2C bus with respective address
+
Wire.onReceive(receive); // receive data function
+
Wire.onRequest(request); // send data function
+
}
+
+
void loop()
+
{
+
// do nothing
+
}
+
+
void receive(int numBytes) // function that runs when data is received
+
{
+
unsigned char c;
+
+
while(Wire.available())
+
{
+
c = Wire.read();
+
if(c == 0x00) // LED off, if byte equals 0
+
{
+
digitalWrite(13, LOW);
+
}
+
else if(c == 0x01) // LED on, if byte equals 1
+
{
+
digitalWrite(13, HIGH);
+
}
+
}
+
}
+
+
void request() // function that runs when data is requested
+
{
+
Wire.write(0xAA); // send 0xAA
+
}</nowiki>
{{RPI-ShieldBridge-TRAILER}}
{{RPI-ShieldBridge-TRAILER}}
Admin
Bureaucrates
,
Administrateurs
29 918
modifications
Menu de navigation
Outils personnels
Se connecter
Espaces de noms
Page
Discussion
Variantes
Affichages
Lire
Voir le texte source
Voir l’historique
Plus
Rechercher
Navigation
ARDUINO
RASPBERRY-PI
[:: PI Hacking ::]
Particle.IO
Micro Python
Imprimante 3D
Actualités
Modifications récentes
Page au hasard
Aide
Outils
Pages spéciales
Version imprimable