dario_dev Napisano Lipiec 22, 2022 Udostępnij Napisano Lipiec 22, 2022 Cześć, Na początek trochę informacji o sprzęcie z jakim mam problem: Arduino MEGA 2560 DFRobot Ethernet Shield W5200 V1.1 Enkoder inkrementalny UCD-IPH00-XXXXX-L100-PRQ Zasilanie całości jest z portu USB komputera Problem Jeżeli podłączę enkoder pod zasilanie z Arduino 5V i dwa piny do pinów 2 i 3 bez zamontowanego Shielda na Arduino to wszystko jest ok i jak obracam enkoderem to na monitorze portu szeregowego mogę na bieżąco odczytać kąt obrotu. Problem zaczyna się gry do Arduino podpinam Ethernet Shield (piny te same co wcześniej) i jak odpalam to na porcie szeregowym jak kręcę enkoderem i wykonam np 5 pełnych obrotów tarczy to mi pokazuje że obrót się wykonał o kilka stopni. Kod programu Wrzucam poniżej kod programu który na ten moment mam, w tym kodzie jest również inicjalizacja tego shielda ethernet, chodzi o to żeby to poprawnie działało w połączeniu z shieldem. /* Web Server A simple web server that shows the value of the analog input pins. using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe modified 02 Sept 2015 by Arturo Guadalupi */ #include <SPI.h> #include <Ethernet.h> #define W5200_nSCS 10 #define W5200_nRST 8 #define W5200_PWDN 9 #define W5200_nINT 3 //unused long randomNumber; bool sendData = false; volatile long temp,angle,counter = 0; float degree = 45.5111; const float piNumber=3.14; float angleInRadian=0; EthernetServer server(80); void DF_W5200_Init(void) { pinMode(W5200_nSCS,OUTPUT); pinMode(W5200_nRST,OUTPUT); pinMode(W5200_PWDN,OUTPUT); pinMode(W5200_nINT,INPUT); //unused digitalWrite(W5200_PWDN,LOW); //Normal Mode Enable digitalWrite(W5200_nRST,LOW); //Hardware reset //delay(10); digitalWrite(W5200_nRST,HIGH); //delay(200); Ethernet.init(W5200_nSCS); } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { counter--; }else{ counter++; } } // 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(192, 168, 0, 102); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): void setup() { DF_W5200_Init(); // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields //Ethernet.init(5); // MKR ETH shield //Ethernet.init(0); // Teensy 2.0 //Ethernet.init(20); // Teensy++ 2.0 //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet // Open serial communications and wait for port to open: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } // start the Ethernet connection and the server: Ethernet.begin(mac, ip); // Check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); while (true) { delay(1); // do nothing, no point running without Ethernet hardware } } else if (Ethernet.hardwareStatus() == EthernetW5100) { Serial.println("W5100 Ethernet controller detected."); } else if (Ethernet.hardwareStatus() == EthernetW5200) { Serial.println("W5200 Ethernet controller detected."); } else if (Ethernet.hardwareStatus() == EthernetW5500) { Serial.println("W5500 Ethernet controller detected."); } if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // start the server server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3 //Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino. //attachInterrupt(1, ai1, RISING); } void loop() { // listen for incoming clients EthernetClient client = server.available(); // Wait a moment for data to arrive // Note: This is NOT a reliable way of doing it! //Serial.println("new client"); // an http request ends with a blank line /*boolean currentLineIsBlank = true; if (client.available()>0) { Serial.println("Client available"); char c = client.read(); if(c == 97) { sendData = true; PrintData(); } else { sendData = false; } } else if(client.available() ==0 && sendData) { PrintData(); } */ //Serial.println(counter); if(counter <= 16384 && counter >= -16384) { angle = counter/degree; angleInRadian = (angle * (2 * piNumber)) / 360; if(counter != temp ) { Serial.println (angleInRadian); Serial.println (angle); temp = counter; } } else { counter = 0; } //delay(1000); } W sieci za bardzo nie mogłem znaleźdź sensownych informacji, dlatego utworzyłem nowy wątek tutaj. Może ktoś z Was miał podobny problem. Link do komentarza Share on other sites More sharing options...
dario_dev Lipiec 26, 2022 Autor tematu Udostępnij Lipiec 26, 2022 Rozwiązałem powyższy problem, poprzez podpięcie zasilania z zasilacza do arduino zamiast zasilania usb, ale pojawił się inny problem, jak podłączę kabel sieciowy do shielda ethernet to przestają mi działać przerwania, przez co jak kręcę enkoderem to nie mogę tego odnotować. Problem się pojawia tylko po włożeniu kabla ethernet do gniazda shielda, jeżeli kabla nie ma to przerwania działają. Ethernet Shield któego używam to DFRobot W5200 v1.1 . Miał ktoś z Was podobny problem ? Link do komentarza Share on other sites More sharing options...
Pomocna odpowiedź
Bądź aktywny - zaloguj się lub utwórz konto!
Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony
Utwórz konto w ~20 sekund!
Zarejestruj nowe konto, to proste!
Zarejestruj się »Zaloguj się
Posiadasz własne konto? Użyj go!
Zaloguj się »