It should look something like this. Just print what comes over the serial. I did not test this.
#include <Wire.h>
void setup() { // Join I2C bus as slave with address 8 Wire.begin(0x8);
// Call receiveEvent when data received Wire.onReceive(receiveEvent);
}
// Function that executes whenever data is received from master void receiveEvent(int howMany) { while (Wire.available()) { // loop through all but the last char c = Wire.read(); // receive byte as a character Serial.println(c); } } void loop() { delay(100); }
In order to see what's going on in the Serial Monitor, you will need to add the following code in setup()
void setup() {
Serial.begin(57600);
}
Note: You can change the speed to 9600. Without that statement, nothing will come out of the Serial Port!
the rows and columns are not labeled. Please can you tell me what the rows signify and what the columns signify and how they line up?
So here is an explanation. There are 2 dashes for each set because you are returning 2 digits. The dashes mean it did not get a response from that anything reporting to have the address. First 3 addresses are blank. Something about not being able to assign them, I'm not positive on that. If a cell is populated, that means it got a response from that address. (in your case it means that the Pi asked if there was anything on the line that was using that address and it responded. So your Pi was able to communicate and it was able to hear the response from the Arduino. Because it is assigned as 0x8, it should appear on the 00 row and under the 8 for column. When accounting for the format not lining up, yours did end up in that place.)
As you can see below, the row signifies what range it is. So of the 2 digit number it it starts with a 1 it will be in the 10 row. 7 will be in 70 row. The column is the last digit.
This is what it would look like if it was all filled with addresses. I am trying to format it correctly so hopefully this works.
the rows and columns are not labeled. Please can you tell me what the rows signify and what the columns signify and how they line up?
So here is an explanation. There are 2 dashes for each set because you are returning 2 digits. The dashes mean it did not get a response from that anything reporting to have the address. First 3 addresses are blank. Something about not being able to assign them, I'm not positive on that. If a cell is populated, that means it got a response from that address. (in your case it means that the Pi asked if there was anything on the line that was using that address and it responded. So your Pi was able to communicate and it was able to hear the response from the Arduino. Because it is assigned as 0x8, it should appear on the 00 row and under the 8 for column. When accounting for the format not lining up, yours did end up in that place.)
As you can see below, the row signifies what range it is. So of the 2 digit number it it starts with a 1 it will be in the 10 row. 7 will be in 70 row. The column is the last digit.
This is what it would look like if it was all filled with addresses. I am trying to format it correctly so hopefully this works.
That table is tremendous! It tells me that the I2C-1 bus is enabled and the the Pi and Arduino can see each other because the Arduino registers an address on the Pi. The wiring is correct and the physical wires are functional. I wonder if you would be so kind as to check my code for mistakes. I’ve triple checked it but I am severely dyslexic and can be blind to mistakes.
This is the python code I am using on the Pi. It compiles and runs as shown in Bill's Dronebot tutorial:
from smbus import SMBus
addr = 0x8
bus = SMBus(1)
numb = 1
print ("Enter 1 for ON or 0 for OFF")
while numb == 1:
ledstate = input(">>>>")
if ledstate == "1":
bus.write_byte(addr, 0x1)
elif ledstate == "0":
bus.write_byte(addr, 0x0)
else:
numb = 0
And this is the code I am using on the Arduino. It also compiles and uploads to the Arduino:
#include <Wire.h>
const int led = 13;
void setup() {
Wire.begin(0x8);
Wire.onReceive(receiveEvent);
pinMode (led, OUTPUT);
digitalWrite(led, LOW);
}
void receiveEvent(int howMany) {
while (Wire.available()) {
char c = Wire.read();
digitalWrite(led, c);
}
}
void loop() {
delay (100);
}
In the Arduino code I have set the variable as led instead of ledPin because I am using the built in led on the Arduino to reduce the number of things that can go wrong. I’ve tested the led with the blink program. Whether I use led or ledPin in the program the physical led does not come on when I hit 1 and enter. If my code is correct, is it possible that, with all configurations disabled as a default, something else needs to be enabled in the Pi for the programs to work?
It took me a really long time trying to spot the difference in your codes. I was really set on looking for a typo or incorrect procedure that I completely missed formatting! By the way, I don't need the code, just Bill.
@Bill21 So, in Python, spacing does matter. In Arduino we use mostly{} to signify what things belong to but in Python we use spaces(tabs). You can read it as if it came to that piece of code, if the next line is indented one space in from the command then it belongs to it. So in his code While and else are related that go on the same line(imagine a vertical line). So inside the While clause, ledstate is requested from input and on that same level and after it the If statement occurs. That means when you have the if statement you will need to indent what it is doing and the elif will need to be on the same imaginary vertical line as the IF.
Looking back, the last else is related to the IF statements and should actually be indented one. At-least in the way it was on the tutorial.
Thanks for taking the time and trouble folks. I've tried the variations in formatting and syntax. They all compile and run but the LED still doesn't come on. Once again the LED worked with the blink program. I've been doing other research. does anyone know if RPI.GPIO comes native with Geany in Raspbian? Or, what I can check to be sure I do have it installed?
Thanks for taking the time and trouble folks. I've tried the variations in formatting and syntax. They all compile and run but the LED still doesn't come on. Once again the LED worked with the blink program. I've been doing other research. does anyone know if RPI.GPIO comes native with Geany in Raspbian? Or, what I can check to be sure I do have it installed?
I know nothing about Genry, but GPIO is installed with Buster for the Pi.
gpio -v will tell you if it's installed. gpio readall will show the state for each Pins.
Unfortunately, Gordon is NO LONG
supporting RPi.GPIO or wiringPi. But with Buster, they are now built-in.
gpiozero has taken over and it needs LESS code then the above.
As for the Arduino, a call to 13 should lite the LED; study the blink.ino
Thanks for taking the time and trouble folks. I've tried the variations in formatting and syntax. They all compile and run but the LED still doesn't come on. Once again the LED worked with the blink program. I've been doing other research. does anyone know if RPI.GPIO comes native with Geany in Raspbian? Or, what I can check to be sure I do have it installed?
Geany is just the editor(IDE) on your computer to make the python file. You must upload the file(assuming you didn't create it directly on the Pi) to your Pi and then execute it. You will have to execute it in the terminal. Running it in Geany is only a test and won't do anything.
Wiring Pi is most likely pre-installed. It is on most distros for Pi.
It will just send a 0 and 1 on a small delay. You can mess around with the timing of the delay by changing the number next to the sleeps. The delay might not be long enough. There is no flag to force an exit in this version. So to end it in the terminal, hold ctrl and C.
You will have to upload it to the Pi.
You can also run that simplified arduino sketch to have it send to serial, just remember to include Serial.begin and set your baud rate.
Thanks for taking the time and trouble folks. I've tried the variations in formatting and syntax. They all compile and run but the LED still doesn't come on. Once again the LED worked with the blink program. I've been doing other research. does anyone know if RPI.GPIO comes native with Geany in Raspbian? Or, what I can check to be sure I do have it installed?
Geany is just the editor(IDE) on your computer to make the python file. You must upload the file(assuming you didn't create it directly on the Pi) to your Pi and then execute it. You will have to execute it in the terminal. Running it in Geany is only a test and won't do anything.
Wiring Pi is most likely pre-installed. It is on most distros for Pi.
It will just send a 0 and 1 on a small delay. You can mess around with the timing of the delay by changing the number next to the sleeps. The delay might not be long enough. There is no flag to force an exit in this version. So to end it in the terminal, hold ctrl and C.
You will have to upload it to the Pi.
You can also run that simplified arduino sketch to have it send to serial, just remember to include Serial.begin and set your baud rate.
We use cookies on the DroneBot Workshop Forums to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.