lucasparis
Member
Hi,
I've tested the wiz820io and an ssd1332 OLED with a teensy 3.2, each separately and they both work.
Now I'm trying to use both at once with different chip select pins.
To test it I have a counter that is displayed on the oled and the upd send receive string example with processing.
At first the counter works fine and the wiz receives some of the processing strings but then the serial monitor shows that the wiz received some random junk upd and the oled freezes.
It seems like a problem with the spi sharing. I've tried wrapping each segment with beginTransaction endTransaction, put pull up resistors on both CS (10k).
I'll also post a picture of my breadboard later.
I'm using the ethernet library straight from paul's github and the oled library and modified adafruit graphics library from sumotoy.
Any hints or ideas?
Here is my code
I've tested the wiz820io and an ssd1332 OLED with a teensy 3.2, each separately and they both work.
Now I'm trying to use both at once with different chip select pins.
To test it I have a counter that is displayed on the oled and the upd send receive string example with processing.
At first the counter works fine and the wiz receives some of the processing strings but then the serial monitor shows that the wiz received some random junk upd and the oled freezes.
Code:
Received packet of size 53394
From 149.79.84.47, port 40219
Contents:
�/08g7�g����zvGM:A�w��-�~
Received packet of size 59142
From 207.170.92.51, port 59013
Contents:
�����_9L���v;��$
It seems like a problem with the spi sharing. I've tried wrapping each segment with beginTransaction endTransaction, put pull up resistors on both CS (10k).
I'll also post a picture of my breadboard later.
I'm using the ethernet library straight from paul's github and the oled library and modified adafruit graphics library from sumotoy.
Any hints or ideas?
Here is my code
Code:
#include <Adafruit_GFX.h>
#include <OLED_SSD1332.h>
/*
Note for Teensy 3.x !!!!!!!!!!!!!!!!!!!
You should choose from those pins for CS and RS:
2,6,9,10,15,20,23
*/
#define cs 15
#define rst 6
#define dc 2
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TRANSPARENT -1
int count = 0;
OLED_SSD1332 display = OLED_SSD1332(cs, dc, rst);
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
//#include <SPI.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 10, 10, 2);
unsigned int localPort = 8888; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
//oled
pinMode(9, OUTPUT);
digitalWrite(9, LOW); // reset the WIZ820io
pinMode(10, OUTPUT);
digitalWrite(10, HIGH); // de-select WIZ820io
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH); // de-select the SD Card
// SPI.setCS(cs);
SPI.setCS(cs);
// SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
display.begin();
display.setBitrate(24000000);
display.setRotation(270);
// SPI.endTransaction();
SPI.setCS(10);
// start the Ethernet and UDP:
// SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
// SPI.endTransaction();
Serial.begin(115200);
// SPI.begin();
}
void loop() {
SPI.setCS(10);
digitalWrite(10, LOW);
delay(2);
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
// gotPacket = true;
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
SPI.endTransaction();
digitalWrite(10, HIGH);
delay(40);
//oled
// if(gotPacket)
// {
SPI.setCS(cs);
digitalWrite(cs, LOW);
delay(2);
SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
display.clearScreen();
display.setTextColor(WHITE);
display.setTextSize(1);
String st;
for(int i = 0; i < 7; i++)
{
if(i == 0)
display.setTextColor(RED);
else
display.setTextColor(WHITE);
display.setCursor(0, i*9);
display.println(count);
}
SPI.endTransaction();
digitalWrite(cs, HIGH);
delay(40);
//gotPacket = false;
// }
count ++;
}
/*
Processing sketch to run with this example
=====================================================
// Processing UDP example to send and receive string data from Arduino
// press any key to send the "Hello Arduino" message
import hypermedia.net.*;
UDP udp; // define the UDP object
void setup() {
udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
//udp.log( true ); // <-- printout the connection activity
udp.listen( true ); // and wait for incoming message
}
void draw()
{
}
void keyPressed() {
String ip = "192.168.1.177"; // the remote IP address
int port = 8888; // the destination port
udp.send("Hello World", ip, port ); // the message to send
}
void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, String ip, int port ) { // <-- extended handler
for(int i=0; i < data.length; i++)
print(char(data[i]));
println();
}
*/