Hey Guys,
i have this project i want to send and receiving messages to a pc from an arduino with i2c-sensor.
i have a small w5500 ethernet-shield and using the ethernet3-libary. the pc has touch designer which gets the sensor data and than send out data which should control a led connected to the arduino.
sending data out from the arduino works perfectly but i have some problems getting the receive done.
i tried to send messages to test with packet sender and with touch designer.
#include <MPU6050_tockn.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet3.h>
#include <FastLED.h>
#include <EthernetUdp3.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 18);
#define IP "192.168.0.17"
#define NUM_LEDS 1
#define DATA_PIN 5
CRGB leds[NUM_LEDS];
unsigned int localPort = 8888; // local port to listen on
EthernetUDP Udp;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
MPU6050 mpu6050(Wire);
void setup() {
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
Ethernet.begin(mac, ip);
//Ethernet.hardreset();
//Ethernet.softreset();
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
mpu6050.update();
int packetSize = Udp.parsePacket();
Udp.beginPacket(IP, 8888);
Udp.print("+");
Udp.print(mpu6050.getTemp());
Udp.print("+");
Udp.print(mpu6050.getAngleX());
Udp.print("+");
Udp.print(mpu6050.getAngleY());
Udp.print("+");
Udp.print(mpu6050.getAngleZ());
Udp.print("+");
Udp.print(mpu6050.getAccX());
Udp.print("+");
Udp.print(mpu6050.getAccY());
Udp.print("+");
Udp.print(mpu6050.getAccZ());
Udp.endPacket();
if (packetSize){
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println(packetBuffer);
}
leds[0] = CRGB(0,255,0);
FastLED.show();
delay(50);
}
system
November 8, 2018, 10:14am
2
but i have some problems getting the receive done.
Since you didn't tell us what the problems are, there doesn't seem much point in your having wasted your time posting.
juliusb
November 10, 2018, 9:51pm
3
hi, sorry for not being that clear.
i just dont get any data from the pc to the arduino,
im sending 3 bytes to control rgb of the led connected to the arduino. when testing with serial.print i dont get any data (just an "=" is printed to the monitor)
then i tried to send the data back via udp.print to test.
i try to parse the data like that:
#include <MPU6050_tockn.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet3.h>
#include <FastLED.h>
#include <EthernetUdp3.h>
#include <string.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 18);
#define IP "192.168.0.17"
#define NUM_LEDS 1
#define DATA_PIN 5
CRGB leds[NUM_LEDS];
unsigned int localPort = 8888; // local port to listen on
EthernetUDP Udp;
#define UDP_TX_PACKET_MAX_SIZE 3
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
byte red;
byte green;
byte blue;
int Red;
int Green;
int Blue;
MPU6050 mpu6050(Wire);
void setup() {
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
mpu6050.update();
int packetSize = Udp.parsePacket();
if (packetSize) {
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
red = packetBuffer[0];
green = packetBuffer[1];
blue = packetBuffer[2];
Red = atoi(red);
Green = atoi(green);
Blue = atoi(blue);
// Serial.print(red);
// Serial.print(green);
// Serial.println(blue);
}
Udp.beginPacket(IP, 8888);
// Udp.print(packetBuffer);
Udp.print(Red);
Udp.print("+");
Udp.print(Green);
Udp.print("+");
Udp.print(Blue);
Udp.print("+");
//// Udp.print(mpu6050.getGyroAngleX());
//// Udp.print("+");
//// Udp.print(mpu6050.getGyroAngleY());
//// Udp.print("+");
//// Udp.print(mpu6050.getGyroAngleZ());
//// Udp.print("+");
//// Udp.print(mpu6050.getGyroX());
//// Udp.print("+");
//// Udp.print(mpu6050.getGyroY());
//// Udp.print("+");
//// Udp.print(mpu6050.getGyroZ());
Udp.endPacket();
//leds[0] = CRGB(0, 255, 0);
//FastLED.show();
delay(20);
}
system
November 12, 2018, 9:03am
4
byte red;
byte green;
byte blue;
int Red;
int Green;
int Blue;
Explain this.
Red = atoi(red);
Green = atoi(green);
Blue = atoi(blue);
And this. What does atoi() take as input? Here's a hint. It is NOT a byte.