Herrx
June 11, 2019, 9:05am
1
Hallo,
ich habe ein Arduino Mega welches ist mit einem Ethernet Shield zusammengesteckt habe. Alles funktioniert. Ich kann via Ethernet auf meine SD-Karte zugreifen.
Jetzt will ich die beiden auf eine Lochrasterplatine nebeneinander löten (habe nicht die Höhe). Welche Verbindungen sind notwendig um die SD-Karte und Ethernet zu nutzen?
ICSP Ports habe ich alle verbunden und MOSI - Pin 11, MISO - Pin 12, CLK - Pin 13 und CS - Pin 10. Die 4 Pins habe ich ebenfalls aufgelegt. Funktioniert aber nicht
Danke schon mal.
uwefed
June 11, 2019, 9:15am
2
Der MEGA hat die SPI Schnittstelle (ICSP) an anderen Pins.
The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.
Grüße Uwe
Herrx
June 11, 2019, 9:28am
3
uwefed:
Der MEGA hat die SPI Schnittstelle (ICSP) an anderen Pins.
SPI - Arduino Reference
Grüße Uwe
Ja aber wie kann es sein, dass es funktioniert wenn ich es gesteckt habe. Wenn ich Port 50-53 auch noch richtig verbinde klappt es auch nicht...
Verwende das Ethernet Shield
Ethernet Shield bei Amazon
und ein normales, originales Mega rev.3
Darf ich die ISCP Ports und die Ports für die SD-Karte (10-13) gleichzeitig verbunden haben?
Das holt sich SPI vom ISCP. Das ist bei UNO und MEGA gleich.
Die SD auf dem Ethernetshield dürfte Pin 4 als CS haben.
Gruß Tommy
Herrx
June 11, 2019, 11:13am
5
Jo Port 4 hat mein SD-Karten Problem gelöst.
Aber mit dem FTP-Server-Beispiel bekomme ich keine Übertragung hin und kann das Arduino auch nicht vom PC aus anpingen.
Wenn ich f drücke:
13:19:17.661 -> Ready. Press f or r
13:19:22.222 -> SD opened
13:19:22.222 -> Command connection failed
13:19:22.256 -> FTP FAIL
/*
FTP passive client for IDE v1.0.1 and w5100/w5200
Posted October 2012 by SurferTim
Modified 6 June 2015 by SurferTim
*/
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
// comment out next line to write to SD from FTP server
#define FTPWRITE
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
// change to your network settings
IPAddress ip( 192, 168, 2, 2 );
IPAddress gateway( 192, 168, 2, 1 );
IPAddress subnet( 255, 255, 255, 0 );
// change to your server
IPAddress server( 1, 2, 3, 4 );
EthernetClient client;
EthernetClient dclient;
char outBuf[128];
char outCount;
// change fileName to your file (8.3 format!)
char fileName[13] = "test.txt";
void setup()
{
Serial.begin(9600);
digitalWrite(10,HIGH);
if(SD.begin(4) == 0)
{
Serial.println(F("SD init fail"));
}
Ethernet.begin(mac, ip, gateway, gateway, subnet);
digitalWrite(10,HIGH);
delay(2000);
Serial.println(F("Ready. Press f or r"));
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'f')
{
if(doFTP()) Serial.println(F("FTP OK"));
else Serial.println(F("FTP FAIL"));
}
if(inChar == 'r')
{
readSD();
}
}
File fh;
byte doFTP()
{
#ifdef FTPWRITE
fh = SD.open(fileName,FILE_READ);
#else
SD.remove(fileName);
fh = SD.open(fileName,FILE_WRITE);
#endif
if(!fh)
{
Serial.println(F("SD open fail"));
return 0;
}
#ifndef FTPWRITE
if(!fh.seek(0))
{
Serial.println(F("Rewind fail"));
fh.close();
return 0;
}
#endif
Serial.println(F("SD opened"));
if (client.connect(server,21)) {
Serial.println(F("Command connected"));
}
else {
fh.close();
Serial.println(F("Command connection failed"));
return 0;
}
if(!eRcv()) return 0;
client.println(F("USER myuser"));
if(!eRcv()) return 0;
client.println(F("PASS mypassword"));
if(!eRcv()) return 0;
client.println(F("SYST"));
if(!eRcv()) return 0;
client.println(F("Type I"));
if(!eRcv()) return 0;
client.println(F("PASV"));
if(!eRcv()) return 0;
char *tStr = strtok(outBuf,"(,");
int array_pasv[6];
for ( int i = 0; i < 6; i++) {
tStr = strtok(NULL,"(,");
array_pasv[i] = atoi(tStr);
if(tStr == NULL)
{
Serial.println(F("Bad PASV Answer"));
}
}
unsigned int hiPort,loPort;
hiPort = array_pasv[4] << 8;
loPort = array_pasv[5] & 255;
Serial.print(F("Data port: "));
hiPort = hiPort | loPort;
Serial.println(hiPort);
if (dclient.connect(server,hiPort)) {
Serial.println(F("Data connected"));
}
else {
Serial.println(F("Data connection failed"));
client.stop();
fh.close();
return 0;
}
#ifdef FTPWRITE
client.print(F("STOR "));
client.println(fileName);
#else
client.print(F("RETR "));
client.println(fileName);
#endif
if(!eRcv())
{
dclient.stop();
return 0;
}
#ifdef FTPWRITE
Serial.println(F("Writing"));
byte clientBuf[64];
int clientCount = 0;
while(fh.available())
{
clientBuf[clientCount] = fh.read();
clientCount++;
if(clientCount > 63)
{
dclient.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) dclient.write(clientBuf,clientCount);
#else
while(dclient.connected())
{
while(dclient.available())
{
char c = dclient.read();
fh.write(c);
Serial.write(c);
}
}
#endif
dclient.stop();
Serial.println(F("Data disconnected"));
if(!eRcv()) return 0;
client.println(F("QUIT"));
if(!eRcv()) return 0;
client.stop();
Serial.println(F("Command disconnected"));
fh.close();
Serial.println(F("SD closed"));
return 1;
}
byte eRcv()
{
byte respCode;
byte thisByte;
while(!client.available()) delay(1);
respCode = client.peek();
outCount = 0;
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
if(outCount < 127)
{
outBuf[outCount] = thisByte;
outCount++;
outBuf[outCount] = 0;
}
}
if(respCode >= '4')
{
efail();
return 0;
}
return 1;
}
void efail()
{
byte thisByte = 0;
client.println(F("QUIT"));
while(!client.available()) delay(1);
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
client.stop();
Serial.println(F("Command disconnected"));
fh.close();
Serial.println(F("SD closed"));
}
void readSD()
{
fh = SD.open(fileName,FILE_READ);
if(!fh)
{
Serial.println(F("SD open fail"));
return;
}
while(fh.available())
{
Serial.write(fh.read());
}
fh.close();
}
Der Sketch ist gemäß einleitendem Kommentar kein FTP-Server, sondern ein FTP-Client.
Ich bezweifle, dass auf IPAddress server( 1, 2, 3, 4 ); ein FTP-Server ist.
Gruß Tommy