We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I know the question was asked long time ago, I managed to fixed an I²C issue yesterday after a long time period of failing. I just had to deactivate/reactivate I²C in RPI settings. No I²C device showed up in i2cdetect before, but after de/reactivating it is working now. Maybe my answer helps someone.
Proposal topic: Processing for ARM devices (such as Raspberry Pi)
[Maksim Surguy, @msurguy on twitter and github]
Project Abstract
I want to make a set of 4-5 complete projects using Processing and Raspberry Pi and will publish tutorials, schematics, videos and code for all projects.
Project Description
In order for new or existing users to get started using Processing with Raspberry Pi, more visual resources that are project-based have to be presented in one central location. I will prepare 4-5 projects that integrate Processing functionality with the IO of the Raspberry Pi in a way that benefits and educates users.
My goal is to continue where others left off, building on top of these works and making more advanced users also happy: https://github.com/processing/processing/wiki/Raspberry-Pi
https://projects.raspberrypi.org/en/projects/introduction-to-processing
Here are some of the projects I propose as the ones demonstrating Processing and Raspberry Pi Integration:
Development Process
(Describe your development process. What is your proposed timeline? What do you expect to have completed by midterm and final?)
I have a lot of experience writing tutorials, e-books and documentation with diagrams, charts and various explainers. For this project, I would prepare and troubleshoot projects starting next week and during the official timeline I will publish the complete tutorials and resources.
By the midterm I plan to have published 3 projects. By the final deadline I plan to have 5 projects published with compete instructions and code. After the deadline I would like to contribute more!
More about you
(What are your interests and experience? Which of the Processing software projects have you used and what was your experience like? Have you contributed to other open source projects? If you have an online portfolio, github account, or other relevant documentation of your work, please include links.)
My online presence:
Couple of recent works that involve me documenting projects with Raspberry Pi:
My interests are generative arts, robots (CNC machines like 3D printers and plotters), IoT (devices like ESP8266 / ESP32, Arduino), augmented creativity.
I’ve been familiar with Processing dating back to 2005 and have used it in quite a few personal projects, mainly for visualizing data and interacting with accelerometers.
One of my most prominent contributions to open source is a website called Bootsnipp that I created over 5 years ago and created over a hundred of initial code snippets. Since then it gathered over 2,000 code snippets for Bootstrap framework that are freely available.
I’m an avid contributor to hundreds of open source projects, from machine learning projects, to Web Development frameworks to data visualization projects.
EXCELLENT as always gohai thank you! what would this world be without you!! :)
not only did it work, but it also allows me to write more than one byte at a time (so writing a whole 64byte page will be faster than one-by-one byte :D )
here's my sample code (gohai's general answer works perfectly!)
import processing.io.*;
I2C eeprom;
void setup() {
eeprom = new I2C(I2C.list()[0]);
eeprom.beginTransmission(0x51);
eeprom.write(0x00);
eeprom.write(0x00);
eeprom.write('H');
eeprom.write('E');
eeprom.write('L');
eeprom.write('L');
eeprom.write('O');
eeprom.endTransmission();
delay(100);
eeprom.beginTransmission(0x51);
eeprom.write(0x00);
eeprom.write(0x00);
char[] in = char(eeprom.read(5));
println(in);
}
and the result of the code was:
[0] 'H'
[1] 'E'
[2] 'L'
[3] 'L'
[4] 'O'
thanks again! )))
What about the following?
import processing.io.*;
I2C eeprom;
void setup() {
erprom = new I2C(I2C.list()[0]);
eeprom.beginTransmission(0x51);
eeprom.write(0x00); // high-byte of address
eeprom.write(0x00); // low-byte of address
eeprom.write(0xAA); // data (test)
eeprom.endTransmission();
delay(100);
eeprom.beginTransmission(0x51);
eeprom.write(0x00); // high-byte of address
eeprom.write(0x00); // low-byte of address
byte[] in = eeprom.read(1);
println(in);
}
Hello, after successfully talking to 3 MCP23017 IO expanders on the I2C bus of my RPi3, i went on to explore the world of external storage, specifically the 24LC256. I've been using the processing.io library, but i've had no luck in correct reading/writing of data onto the chip. Can this be done with this library or do i need to get to lower level wiring library stuff? I'm not really that experienced with the datasheet commands reading,
here's that piece of code so far :
import processing.io.*;
I2C compass;
void setup() {
compass = new I2C(I2C.list()[0]);
compass.beginTransmission(0x51);
compass.write(0x00);
compass.write(0x00);
compass.endTransmission();
delay(100);
compass.beginTransmission(0x51);
compass.write(0x00);
byte[] in = compass.read(1);
println(in);
}
and the result i get from this is 0x30 instead of 0x00...
any help would be much appreciated!! Vangelis
P.S. yes using i2cdetect shows me the eeprom being on the 0x51 address :D
Thank you @pbp. Very timely! I've been messing about with I2C and your examples clarified a number of points for me. Who knows. Maybe I'll brave the humidity and pressure sensors too. Kudos. :)
Hello, I have written some code to implement functionalities for the I2C devices in the Sense HAT. You can find them here: https://github.com/PBernalPolo/RPiModules
I thought it might be interesting for someone looking for examples of I2C communication.
@grimofdoom Feel free to post your I2C code so that we can have a look. The IO library comes with some I2C examples that could be informative (e.g. I2CCompass).
You can double-check your wiring by running i2cdetect -y 1
in a terminal. The address of the PN532 need to show up there.
i am using a PN532 (NFC read/write) , connected to the Raspberry Pi over the I2C ports (SCL to 28, SDA to 27). When using the build in library of I2C, it does not find any I2C devices connected (writes nothing). I am new to I2C (and specially NFC), but I have learned that to write/read, it needs to be in 7-bit format (with an 8th bit being read or write), but I do not know if it can be extended (I need to write to 4Kb tags), and if I can manually perform the operations with a home-made library.
I got my code from https://processing.org/reference/libraries/io/I2C_list_.html .What I do not get, is why you cannot just super simply define the SCL and SDA ports.
I also tried writing ( https://processing.org/reference/libraries/io/I2C_write_.html ). But the initialized list is at an error with a size of '0', which I do not know if it can or should be larger...
@The_Idiot Let me try to answer this: a system might have more than one I2C interface - there is thus a list()
method to retrieve an array of available interface names.
Try:
printArray(I2C.list());
To start communicating with a "slave" device connected to any of those I2C busses, you construct a new I2C object by passing the interface name to it's constructor like e.g.:
i2c = new I2C("i2c-2");
And the snippet you posted will simply attempt to use the first I2C interface found...
Thank you for your response. I don't fully understand the arguments - especially:
i2c = new I2C(I2C.list()[0]);
I am trying to get processing to read in an array of 9 bytes (processing will be running on a pi). I should point out that I'm a beginner when it comes to both processing and i2c. And the pi for that matter!
Do you mean this example?
What about it don't you understand -- or what are you trying to do that it doesn't demonstrate?
Does anyone have a well commented i2c example? I don't really follow the example on the site
You can explain it better. Why not use your serial word?
Oops, I actually forgot to put the code in my previous post! Sorry about that, here's the Arduino version (which only has the nunchuck_get data added in)
/*
* NunchuckPrint
*
* 2007 Tod E. Kurt, http://todbot.com/blog/
*
* The Wii Nunchuck reading code is taken from Windmeadow Labs
* http://www.windmeadow.com/node/42
*/
#include <Wire.h>
void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr
nunchuck_init(); // send the initilization handshake
Serial.print ("Finished setup\n");
}
void loop()
{
nunchuck_get_data();
accx = nunchuck_accelx(10);
accy = nunchuck_accely(50);
zbut = nunchuck_zbutton(100);
cbut = nunchuck_cbutton(150);
print(accx);
print(',');
print(accy);
print(',');
print(zbut);
print(',');
println(cbut);
delay(100); // the time in milliseconds between redraws
}
//
// Nunchuck functions
//
static uint8_t nunchuck_buf[6]; // array to store nunchuck data,
// Uses port C (analog in) pins as power & ground for Nunchuck
static void nunchuck_setpowerpins()
{
#define pwrpin PORTC3
#define gndpin PORTC2
DDRC |= _BV(pwrpin) | _BV(gndpin);
PORTC &=~ _BV(gndpin);
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize
}
// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
{
Wire.begin(); // join i2c bus as master
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x40); // sends memory address
Wire.write(0x00); // sends sent a zero.
Wire.endTransmission(); // stop transmitting
}
// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
{
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x00); // sends one byte
Wire.endTransmission(); // stop transmitting
}
// Receive data back from the nunchuck,
int nunchuck_get_data()
{
int cnt=0;
Wire.requestFrom (0x52, 6); // request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
cnt++;
}
nunchuck_send_request(); // send request for next data payload
// If we recieved the 6 bytes, then go print them
if (cnt >= 5) {
return 1; // success
}
return 0; //failure
}
// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits. That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
{
static int i=0;
int joy_x_axis = nunchuck_buf[0];
int joy_y_axis = nunchuck_buf[1];
int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;
int z_button = 0;
int c_button = 0;
// byte nunchuck_buf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((nunchuck_buf[5] >> 0) & 1)
z_button = 1;
if ((nunchuck_buf[5] >> 1) & 1)
c_button = 1;
if ((nunchuck_buf[5] >> 2) & 1)
accel_x_axis += 2;
if ((nunchuck_buf[5] >> 3) & 1)
accel_x_axis += 1;
if ((nunchuck_buf[5] >> 4) & 1)
accel_y_axis += 2;
if ((nunchuck_buf[5] >> 5) & 1)
accel_y_axis += 1;
if ((nunchuck_buf[5] >> 6) & 1)
accel_z_axis += 2;
if ((nunchuck_buf[5] >> 7) & 1)
accel_z_axis += 1;
Serial.print(i,DEC);
Serial.print("\t");
Serial.print("joy:");
Serial.print(joy_x_axis,DEC);
Serial.print(",");
Serial.print(joy_y_axis, DEC);
Serial.print(" \t");
Serial.print("acc:");
Serial.print(accel_x_axis, DEC);
Serial.print(",");
Serial.print(accel_y_axis, DEC);
Serial.print(",");
Serial.print(accel_z_axis, DEC);
Serial.print("\t");
Serial.print("but:");
Serial.print(z_button, DEC);
Serial.print(",");
Serial.print(c_button, DEC);
Serial.print("\r\n"); // newline
i++;
}
// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}
and the Processing code I've been working as I try to understand the Serial libraries further:
import processing.serial.*;
// The serial port:
Serial myPort;
String inString; // Input string from serial port
static final int VALUES = 3, PORT_IDX = 0, BAUDS = 9600;
int[] vals = new int[VALUES];
boolean dataArrived;
void setup (){
size(400,200);
frameRate(30);
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 9600);
// Send a capital A out the serial port:
myPort.write(185);
}
void draw() {
boolean a = false;
if (!a) {
a = true;
if (a) {
random(0, 10) ;
}
while (myPort.available() > 0) { // returns the number of bytes available
int inByte = myPort.read(); // Returns a number between 0 and 255 for the
// next byte that's waiting in the buffer. Returns -1 if there is no byte,
// although this should be avoided by first cheacking available() to see if data is available.
println(inByte);
}
void serialEvent(Serial p) {
inString = p.readString();
}
}
So I've tried the Processing code you posted and am receiving the following in BAUDRATE 19200, which compared to 9600 LOOKS a lot better, haha.
98 : 213,113 but:1,1
98 : 62 joy:254,128 acc:153,93,97 but:1,1
98 : 1,1
98 : 60 joy:139,128 acc:200,113,116 but:1,1
98 : 61 joy:254,128 acc:166,93,113 but:1,1
98 : 62 joy:254,128 acc:153,93,97 but:1,1
98 : Finished setup
99 : 0 joy:255,255 acc:258,258,258 but:1,1
105 : 1 joy:0,128 acc:174,111,138 but:1,1
111 : 2 joy:128,128 acc:166,132,126 but:1,1
117 : 3 joy:128,128 acc:217,165,176 but:1,1
123 : 4 joy:128,128 acc:181,130,125 but:1,1
129 : 5 joy:128,128 acc:179,130,121 but:1,1
136 : 6 joy:128,128 acc:181,131,121 but:1,1
142 : 7 joy:128,128 acc:179,131,121 but:1,1
148 : 8 joy:128,128 acc:182,132,123 but:1,1
154 : 9 joy:128,128 acc:181,132,121 but:1,1
160 : 10 joy:128,128 acc:181,130,121 but:1,1
166 : 11 joy:128,128 acc:179,130,121 but:1,1
172 : 12 joy:128,128 acc:181,130,121 but:1,1
179 : 13 joy:128,128 acc:179,132,121 but:1,1
185 : 14 joy:128,128 acc:179,132,121 but:1,1
191 : 15 joy:128,128 acc:181,132,121 but:1,1
197 : 16 joy:128,128 acc:179,130,121 but:1,1
203 : 17 joy:128,128 acc:179,132,121 but:1,1
209 : 18 joy:128,128 acc:181,132,121 but:1,1
215 : 19 joy:128,128 acc:181,132,123 but:1,1
221 : 20 joy:128,128 acc:179,130,121 but:1,1
227 : 21 joy:128,128 acc:181,130,123 but:1,1
234 : 22 joy:128,128 acc:181,132,121 but:1,1
240 : 23 joy:128,128 acc:181,132,121 but:1,1
246 : 24 joy:128,128 acc:179,132,123 but:1,1
252 : 25 joy:128,128 acc:181,130,123 but:1,1
258 : 26 joy:128,128 acc:181,132,123 but:1,1
264 : 27 joy:128,128 acc:179,132,123 but:1,1
270 : 28 joy:128,128 acc:181,130,123 but:1,1
277 : 29 joy:128,128 acc:179,132,123 but:1,1
283 : 30 joy:128,128 acc:181,130,123 but:1,1
289 : 31 joy:128,128 acc:179,130,123 but:1,1
295 : 32 joy:128,128 acc:181,132,123 but:1,1
301 : 33 joy:128,128 acc:179,132,123 but:1,1
307 : 34 joy:128,128 acc:181,130,123 but:1,1
313 : 35 joy:128,128 acc:181,130,123 but:1,1
320 : 36 joy:128,128 acc:181,132,123 but:1,1
326 : 37 joy:128,128 acc:181,132,123 but:1,1
332 : 38 joy:128,128 acc:179,130,123 but:1,1
338 : 39 joy:128,128 acc:181,130,123 but:1,1
344 : 40 joy:128,128 acc:181,130,123 but:1,1
350 : 41 joy:128,128 acc:179,132,123 but:1,1
356 : 42 joy:128,128 acc:179,132,123 but:1,1
363 : 43 joy:128,128 acc:179,132,123 but:1,1
369 : 44 joy:128,128 acc:179,130,123 but:1,1
375 : 45 joy:128,128 acc:179,132,123 but:1,1
381 : 46 joy:128,128 acc:179,132,123 but:1,1
387 : 47 joy:128,128 acc:179,130,123 but:1,1
393 : 48 joy:128,128 acc:179,130,123 but:1,1
399 : 49 joy:128,128 acc:181,130,123 but:1,1
406 : 50 joy:128,128 acc:179,132,123 but:1,1
412 : 51 joy:128,128 acc:179,132,123 but:1,1
418 : 52 joy:128,128 acc:179,130,123 but:1,1
424 : 53 joy:128,128 acc:181,130,123 but:1,1
430 : 54 joy:128,128 acc:181,132,123 but:1,1
436 : 55 joy:128,128 acc:179,132,123 but:1,1
442 : 56 joy:128,128 acc:179,132,123 but:1,1
448 : 57 joy:128,128 acc:179,130,123 but:1,1
455 : 58 joy:128,128 acc:179,130,123 but:1,1
and BAUDRATE 9600 -- which was much more longer, but I put a snippet of it here just so you can see how it looked for rows and rows of code:
99 : ½Äþ½Ä§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠjŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)(ˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þŠŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠjŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)(ˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þ??1kúÿ¼§!L)
99 : Œ
99 : Œ
153 : ŒüO•=þ?§¥Š!)ˆˆHˆŒüO•?þ¼§¥ŠÉˆˆHŠŒüO•?þ§¥Š)ˆˆkŠŒüO•?þ¼§¥Š)ˆˆHŠHˆüO•?þħ¥Š)ˆˆHŠŒüO•?þ¼§¥Š)ˆˆHŠŒüO•?þ"§¥Š)ˆˆHŠŒüO•?þ¼§¥Š)ˆˆHŠHŒüO•?þ?§¥
1694 : )ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆªHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆHŠŒüO•#þ½Ä§¥Š)ˆˆHŠŒüO•?þµÄs¥Š)ˆˆHŠŒüO•?þ½Ä§¥lŠ)ˆˆHŠŒüO•?þ¥Ä§¥Šc)ˆˆHŠŒüO•?þħ¥Š)*ˆHŠŒüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠlüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüO•?þjt§¥Š)ˆˆHŠŒüO•?þzħeŠ)ˆˆHŠŒüO•?þjħ¥Š)ˆˆHŠŒüï•?þzħ¥ŠÉˆˆHŠŒüO•?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠhŒüO•?þ!œ§¥*)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•?þ¡œ§¥Š)HŒHŠŒüO•?þ)œ§¥Š)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•?þ!œ§¥Š)ˆˆHŠŒüO•"þ)œ§¥Š)ÈŒHŠHˆüO•?þ)œ§¥Š)ˆˆHªŒüO•?þ1œ§¥Š)ˆˆHŠŒüO•?þ1œ§¥Šc)ˆˆHŠŒüO•?þKħ¥Š)*ˆHŠŒüO•?þ[ħ¥Š)HŒHŠŒüO•?þKħ¥Š)ˆˆHŠlüO•?þ[ħ¥Š()ˆˆHŠŒüO•?þkħ¥Š)ˆˆHŠŒüO•?þ{ħ¥Š)HŒhŠHˆüO•?þkħ¥Š)ˆˆHŠküO•?þ{ħ¥Š)ˆˆHŠŒüO•?þKħ¥Š)ˆˆHŠŒüO•?þ[ħ¥Š)HŒHŠŒüO•?þˆ¼§¥Š)ˆˆHŠhŒüO•?þˆ¼§¥Š)ˆˆHŠŒüO•?þм§¥Š)ˆˆHŠŒüO•?þk¼§¥Š)ˆˆHŠŒüO•?þˆ¼§¥Š)ˆˆHŠkŒüO•?þˆ¼§¥Š)ˆˆHŠŒüO•?þм§¥Šd)HŒHŠŒüO•?þм§¥Š)ˆˆHŠŒüO•?þŒ¼§¥Š)HŒHªHˆüO•?þŒ¼§¥dŠ)HŒHŠHˆüO•?þKħ¥Š)ˆˆHŠŒüO•?þ[ħ¥Š)ˆˆHŠŒüO•?þKħ¥Š)ˆˆHˆŒüO•?þ[ħ¥Š)ˆˆHŠlüO•?þkħ¥Š)ˆˆHŠŒüO•?þ{ħ¥Š)ˆˆHŠŒüO•?þkt§¥Š)ˆˆHŠŒüO•?þ{ħeŠ)ˆˆHˆHˆüO•?þKħ¥Š!)ˆˆHˆŒüO•?þ[ħ¥ŠÉˆˆHˆHˆüO•?þˆ¼§¥Š)ˆˆHˆHˆüO•?þˆ¼§RŠ)HŒHŠŒüO•?þм§¥Š)ˆˆHŠHˆüO•?þм§¥Š)ˆˆHŠŒüO•?þˆ¼§¥Š)ˆªHŠHˆüO•?þˆ¼w¥Š)ˆˆHˆHˆüO•?þм§¥Š)HŒHˆŒŒO•?þм§¥Š)ˆˆHŠŒüO•?þŒ¼§¥Š)ˆHŠŒüO•?þŒ¼§¥Š)ˆˆHªŒüO•?þJħ¥Š)ˆˆHŠHˆüO•?þZħ¥Š)ˆˆHŠŒüOe?þJħ¥Š)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüO•?þjħ¥Š)ˆˆHŠlüO•?þzħ¥Š)ˆˆHŠHˆüO•?þjħ¥Š©ˆˆHŠHˆüO•?þzħ¥Š)ˆˆhŠŒüO•?þJħeŠ)ˆˆHŠŒüO•?þZħ¥Š)ˆˆHŠŒüï•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠhŒüO•?þħ¥*)ˆˆHˆŒüO•?þµÄ§¥Š)ˆˆHŠŒüO•þ]ħ¥Š)ˆˆHŠŒüO•?þµÄg¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥?§¥Š)ˆˆHŠlüO•?þ¥§¥Š()ˆˆHŠŒüO•?þ¥§¥Š)HŒHˆHˆüO•?þ¥Ä§¥Š)HŒjŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)HŒHŠŒüO•?þ¥Ä§¥Š)ˆˆHˆŒüO•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥?§¥Š)ˆˆHˆ*ˆüO•?þħ¥Š)ˆˆHˆŒüO•?þ?§¥Š)ˆˆHŠHˆüO•%þ§¥Š)ˆˆHˆHˆüO•?þ§¥Š)ˆˆH¨HˆüO•?þħ¥Š)HŒHŠHˆ…O•?þħ¥Š)ˆˆHŠŒüOu?þħ¥Š)êŒHŠŒüO•?þħ¥Š)ˆˆHˆŒüO•?þħ¥Š)HŒHŠHˆüO•?þ?§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥ŠéˆˆHŠHˆüO•?þ¥?§¥Š)ˆˆkŠHˆüO•?þ¥§SŠ)ˆˆHŠHˆüO•?þ¥§¥Š)ˆˆHŠHˆüå•?þ¥Ä§¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥Ä§¥Š)ˆˆHŠHˆ„O•?þ¥Ä§¥Šd)ˆˆHˆHˆüO•?þ¥?§¥Š)(ˆHŠŒüO•?þħ¥Š)ˆˆHˆHˆüO•?þ?§¥Š)ˆˆHˆHˆüO•?þ§¥Š)ˆˆHŠHˆüO•?þ§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHˆŒüO•?þħeŠ)HŒHŠHˆüO•?þħ¥Š)ˆˆHŠŒüï•?þħ¥ŠÉˆˆHŠŒüO•?þ#§¥Š)ˆˆHˆŒüO•?þ?§¥Š)ˆˆHŠHˆüO•?þµÄ§¥Š)HŒHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•%þU§¥Š)ˆˆHŠHˆüO•?þµs¥Š)ˆˆHŠHˆüO•?þµÄ§¥lŠ)HŒHŠHˆüO•?þµÄ§¥Š)ˆˆHŠŒüOu?þµÄ§¥Š)*ˆHŠŒüO•?þµÄ§¥Š)ˆˆHˆŒüO•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ?§¥Š()ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠHˆüO•?þ½?§¥Š)ˆˆkŠŒüO•?þ½§¥Š)ˆˆHˆHŒüO•?þ½§¥*)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHˆHˆüO•?þ½Ä§¥Š)ˆˆHŠŒüO•?þ½Äw¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHŠHˆŒO•?þ½Ä§¥Šd)ˆˆHŠHˆüO•?þC?§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ?§¥eŠ)ˆˆHˆŒüO•?þµ§¥Š)ˆˆHŠHˆüOc?þµ§¥Š)ˆˆHŠŒüO•?þµÄ§¥Š)ˆˆhŠŒüO•?þµÄ§eŠ)ˆˆHŠŒüO•?þµÄ§¥Š)HŒHŠŒüï•?þµÄ§¥Š)ˆˆHŠHˆüO•?þµ#§¥Š)ˆˆHŠHˆüO•?þµ?§¥Š)ˆˆHŠŒüO•?þ½Ä§¥Š)ˆˆHˆHˆüO•?þ½?§¥Š)HŒHŠHˆüO•-þ½§¥Š)ˆ©HŠHˆüO•?þ½§¥Š)ˆˆHŠHˆüO•?þ½Ä§¥lŠ)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHˆŒüOU?þ½Ä§¥Š)èŒHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠHˆüO•?þ½Ä§¥Š)ˆˆHŠLüO•?þ½?§¥Š()ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠHˆüO•?þ¥?§¥Š)ˆˆhŠHˆüO•?þ¥§UŠ)ˆˆHŠŒüO•?þ¥§¥Š)ˆˆHˆHˆüç•?þ¥Ä§¥ŠÎˆˆHˆHˆüO•?þ¥Ä§¥Š)ˆ¨HŠHˆüO•?þ¥Äg¥Š)ˆˆHŠŒüO•?þ¥Ä§¥Š)ˆˆHŠŒ¼O•?þ¥Ä§¥ŠD)ˆˆHˆHˆüO•?þe?§¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHŠŒüO•?þ?§¥dŠ)ˆˆHŠŒüO•?þ§¥Š)ˆˆHŠŒüOe?þ§¥Š)+ˆHŠHˆüO•?þħ¥Š)ˆˆHŠŒüO•?þħ¥Š)ˆˆHŠHhüO•?þħ¥Š )ˆˆHŠHˆüO•?þħ¥ŠÉˆˆHŠŒüO•?þħ¥Š)ˆˆHŠHˆüO•?þ?§SŠ)ˆˆHŠHˆüO•?þJ¼§¥*)ˆˆHŠŒüO•?þJ?§¥Š)ˆˆHŠŒüO•?þJ¼§¥Š)ˆªHŠHˆüO•?þJw¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒ„O•?þJħ¥Š)ˆˆHˆHˆüO•?þJ¼§¥Š)(ˆHŠHˆüO•?þJħ¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒüO•?þJ?§¥Š)ˆˆHŠHˆüOb?þZ¼§¥Š)ˆˆHˆHˆüO•?þZ?§¥Š)HŒHˆŒüO•?þZ¼§¥Š)ˆˆHŠHˆüO•?þZ§¥Š)ˆˆHŠŒüï•?þZ¼§¥ŠÏˆˆHŠHˆüO•?þZħ¥Š)ˆˆHŠHˆüO•?þZ¼§¥Š)ˆˆHŠ*ˆüO•?þZħ¥Š)ˆˆHŠHˆ¼O•?þZ¼§¥ŠD)ˆˆHŠŒüO•?þŠ?§¥Š)HŒHˆHˆüO•?þJ¼§¥Š)ˆˆHˆŒüO•?þJ?§¥Š)HŒHŠHˆüO•?þJ¼§¥Š)ˆˆHŠŒüO•?þJ§¥Š)ˆˆHŠŒüO•?þJ¼§¥Š)ˆˆHˆHˆüO•?þJħ¥Š)ˆˆHŠHˆüO•?þJ¼§¥Š )ˆˆHŠŒüO•?þJħ¥ŠéˆˆHŠŒüO•?þJ¼§¥Š)ˆˆkŠHˆüO•?þJ?§¥Š)ˆˆHŠHˆüO•?þZ¼§¥*)ˆˆHŠHˆüO•?þZ?§¥Š)ˆˆHŠHˆüO•=þZ¼§¥Š)ˆ¨HŠHˆüO•?þZw¥Š)ˆˆHŠHˆüO•?þZ¼§¥Š)ˆˆHŠHˆüO•?þZħ¥Šd)ˆˆHŠHˆüO•?þZ¼§¥Š)(ˆHŠHˆüO•?þZħ¥Š)ˆˆHªHˆüO•?þZ¼§¥eŠ)ˆˆHŠHˆüO•?þZ?§¥Š)HŒHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þj?§¥Š)ˆˆhŠHˆüO•?þj¼§¥Š)ˆˆHˆHküO•?þj§¥Š)ˆˆHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þjħ¥Š)ˆ¨HˆŒüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þjħ¥Š)ˆˆHŠHˆüO•?þj¼§¥Š)ˆˆHŠHˆüO•?þj?§¥Š)ˆˆHˆHˆüO•?þz¼s¥Š)ˆˆHŠHˆüO•?þz?§¥lŠ)HŒHŠHˆüO•?þz¼§¥Š)HŒHŠHˆüOu?þz§¥Š)ˆˆHŠHˆüO•?þz¼§¥Š)ˆˆHŠŒüO•?þzħ¥Š)ˆˆHŠlüO•?þz¼§¥Š )HŒHŠHˆüO•?þzħ¥ŠéˆˆHŠHˆüO•?þz¼§¥Š)ˆˆkŠHˆüO•?þz?§¥Š)ˆˆHŠHˆüO•?þj¼§¥
If I'm not mistaken, considering how the 19200 one went, I suppose it means I can edit it to the point where I can do my original purpose with it, right? (Though honestly I'm just happy the data is FINALLY being seen in Processing! That was the only part I never saw in all my attempts.)
Hi
Can someone provide me leads on how to use get data from MPU6050 (Using I2C) in Raspberry PI3 please?
Thanks S
Not sure how the forum feels about double posting, but I thought I should update: I changed the code in the Arduino to see if I could get my Processing code to work. While it hasn't done anything (in other words, I'm still stuck on my original problem), I'm posting the new code here:
/*
* NunchuckPrint
*
* 2007 Tod E. Kurt, http://todbot.com/blog/
*
* The Wii Nunchuck reading code is taken from Windmeadow Labs
* http://www.windmeadow.com/node/42
*/
#include <Wire.h>
void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr
nunchuck_init(); // send the initilization handshake
Serial.print ("Finished setup\n");
}
void loop()
{
nunchuck_get_data();
nunchuck_print_data();
delay(100);
}
//
// Nunchuck functions
//
static uint8_t nunchuck_buf[6]; // array to store nunchuck data,
// Uses port C (analog in) pins as power & ground for Nunchuck
static void nunchuck_setpowerpins()
{
#define pwrpin PORTC3
#define gndpin PORTC2
DDRC |= _BV(pwrpin) | _BV(gndpin);
PORTC &=~ _BV(gndpin);
PORTC |= _BV(pwrpin);
delay(100); // wait for things to stabilize
}
// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
{
Wire.begin(); // join i2c bus as master
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x40); // sends memory address
Wire.write(0x00); // sends sent a zero.
Wire.endTransmission(); // stop transmitting
}
// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
{
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.write(0x00); // sends one byte
Wire.endTransmission(); // stop transmitting
}
// Receive data back from the nunchuck,
int nunchuck_get_data()
{
int cnt=0;
Wire.requestFrom (0x52, 6); // request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.read());
cnt++;
}
nunchuck_send_request(); // send request for next data payload
// If we recieved the 6 bytes, then go print them
if (cnt >= 5) {
return 1; // success
}
return 0; //failure
}
// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits. That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
{
static int i=0;
int joy_x_axis = nunchuck_buf[0];
int joy_y_axis = nunchuck_buf[1];
int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;
int z_button = 0;
int c_button = 0;
// byte nunchuck_buf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((nunchuck_buf[5] >> 0) & 1)
z_button = 1;
if ((nunchuck_buf[5] >> 1) & 1)
c_button = 1;
if ((nunchuck_buf[5] >> 2) & 1)
accel_x_axis += 2;
if ((nunchuck_buf[5] >> 3) & 1)
accel_x_axis += 1;
if ((nunchuck_buf[5] >> 4) & 1)
accel_y_axis += 2;
if ((nunchuck_buf[5] >> 5) & 1)
accel_y_axis += 1;
if ((nunchuck_buf[5] >> 6) & 1)
accel_z_axis += 2;
if ((nunchuck_buf[5] >> 7) & 1)
accel_z_axis += 1;
Serial.print(i,DEC);
Serial.print("\t");
Serial.print("joy:");
Serial.print(joy_x_axis,DEC);
Serial.print(",");
Serial.print(joy_y_axis, DEC);
Serial.print(" \t");
Serial.print("acc:");
Serial.print(accel_x_axis, DEC);
Serial.print(",");
Serial.print(accel_y_axis, DEC);
Serial.print(",");
Serial.print(accel_z_axis, DEC);
Serial.print("\t");
Serial.print("but:");
Serial.print(z_button, DEC);
Serial.print(",");
Serial.print(c_button, DEC);
Serial.print("\r\n"); // newline
i++;
}
// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
{
x = (x ^ 0x17) + 0x17;
return x;
}
I'm still using the same board and adapter, by the by!
@thatdude333 This PWM/Servo controller is hooked up to the Raspberry Pi using the I2C bus. You can use the I2C class of Processing's Hardware I/O library to send command to the device. See this example for how to do so in general. For the specific commands the controller expects you would have to consult its datasheet, or - perhaps - have a peek inside the Python library to see what values get send.
@shushustorm GPIO pins 2 and 3 are used for the I2C bus. I haven't attempted to using those myself for GPIO, but I wouldn't be surprised if it won't work.
Try GPIO 4 and GPIO 17 instead. https://pinout.xyz/
I am reading data from a sensor via I2C using an MSP432 Launchpad. I am trying to send this data to Processing via UART, but the data is almost always corrupted. I have verified using a logic analyzer that I am reading and sending the correct data from the MSP432. The following while loop is my code from CCS.
while (1)
{
if (P6IN & BIT7)
{
Setup_Register(0x49, 0x08, 0x20);
X1 = Read_Data_Register(0x00);
X2 = Read_Data_Register(0x01);
Y1 = Read_Data_Register(0x02);
Y2 = Read_Data_Register(0x03);
MAP_UART_transmitData(EUSCI_A0_BASE, 0x0a);
UART_Transmit(X1);
UART_Transmit(X2);
UART_Transmit(Y1);
UART_Transmit(Y2);
}}
The follwing is my code from Processing.
import processing.serial.*;
Serial myPort;
int X1, X2, Y1, Y2;
float h, v;
void setup() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[3], 19200);
}
void draw() {
byte[] inBuffer = new byte[8];
while(myPort.available() > 0) {
myPort.readBytesUntil(0x0a);
myPort.readBytes(inBuffer);
X1 = (inBuffer[1] << 8) + inBuffer[0];
X2 = (inBuffer[3] << 8) + inBuffer[2];
Y1 = (inBuffer[5] << 8) + inBuffer[4];
Y2 = (inBuffer[7] << 8) + inBuffer[6];
println("X1: " + hex(X1) + "\tX2: " + hex(X2) + "\tY1: " + hex(Y1) + "\tY2: " + hex(Y2));
}
}
Most of the time, the data displayed on Processing is -8224. Sometimes, they are random positive and negative numbers that jump around. What could be causing this issue? Any help is appreciated!