Fórum témák

» Több friss téma
Fórum » Arduino
A klónok CH340 Soros-USB illesztőjének drivere (Letöltés)
Lapozás: OK   174 / 854
(#) atus1981 válasza ALI hozzászólására (») Dec 17, 2015 /
 
°. Fok jele. Mégis csak szebb a 23.63°C
(#) ALI válasza atus1981 hozzászólására (») Dec 17, 2015 /
 
Tényleg szebb.
Én még messze vagyok hogy ilyeneket tudjak
(#) atus1981 válasza ALI hozzászólására (») Dec 17, 2015 /
 
Nagyszerű.
Melyik 2 gomb működik?
(#) kapu48 válasza ALI hozzászólására (») Dec 17, 2015 /
 
És hogyan is nézki az összefésült programod?
Mert még mindég nem tudjuk miröl beszélünk!
(#) ALI válasza kapu48 hozzászólására (») Dec 18, 2015 /
 
Így néz ki a kettő egyben.
Ez még csak próbálkozás mert a teljes program nem így fog kinézni.
Arra gondoltam a két analóg bemenet akad össze.
Így csak a LEFT és a RIGHT gombok működnek.
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(12, 13, 8, 9, 10, 11);
  3. float tempC;
  4. int reading;
  5. int tempPin = A1;
  6. int lcd_key     = 0;
  7. int adc_key_in  = 0;
  8. #define btnRIGHT  0
  9. #define btnUP     1
  10. #define btnDOWN   2
  11. #define btnLEFT   3
  12. #define btnSELECT 4
  13. #define btnNONE   5
  14.  
  15.  
  16. int read_LCD_buttons()
  17. {
  18.  adc_key_in = analogRead(0);      
  19.  
  20.  
  21.  if (adc_key_in > 1000) return btnNONE;
  22.  // For V1.1 us this threshold
  23.  if (adc_key_in < 50)   return btnRIGHT;  
  24.  if (adc_key_in < 250)  return btnUP;
  25.  if (adc_key_in < 450)  return btnDOWN;
  26.  if (adc_key_in < 650)  return btnLEFT;
  27.  if (adc_key_in < 850)  return btnSELECT;  
  28.  
  29.  
  30.  
  31.  
  32.  return btnNONE;  // when all others fail, return this...
  33. }
  34. void setup()
  35. {
  36.  
  37. lcd.begin(16, 2);
  38. }
  39.  
  40. void loop()
  41. {
  42. reading = analogRead(tempPin);
  43. tempC = reading / 9.31;
  44.  lcd.setCursor(0, 0);
  45.   lcd.print("SZ:");
  46.   lcd.print(tempC);
  47.   lcd.print("C");
  48. delay(1000);
  49. lcd.setCursor(0,1);            
  50.  lcd_key = read_LCD_buttons();  
  51.  
  52.  switch (lcd_key)              
  53.  {
  54.    case btnRIGHT:
  55.      {
  56.      lcd.print("RIGHT ");
  57.      break;
  58.      }
  59.    case btnLEFT:
  60.      {
  61.      lcd.print("LEFT   ");
  62.      break;
  63.      }
  64.    case btnUP:
  65.      {
  66.      lcd.print("UP    ");
  67.      break;
  68.      }
  69.    case btnDOWN:
  70.      {
  71.      lcd.print("DOWN  ");
  72.      break;
  73.      }
  74.    case btnSELECT:
  75.      {
  76.      lcd.print("SELECT");
  77.      break;
  78.      }
  79.      case btnNONE:
  80.      {
  81.      lcd.print("NONE  ");
  82.      break;
  83.      }
  84.  }
  85.  
  86. }
(#) atus1981 válasza ALI hozzászólására (») Dec 18, 2015 /
 
Szerintem csinálj egy olyat, hogy kiíratod soros portra az adc_key_in értékét, és felírod amit kaptál bizonyos gombok lenyomásakor.
Aztán ennek megfelelően módosítod eme képlet alapján: (adc_key_in > 800 and adc_key_in < 820).
Persze a megfelelő helyekre a saját kapott értékét írd.
(#) ALI válasza atus1981 hozzászólására (») Dec 18, 2015 /
 
Köszi az ötletet kipróbálom.
(#) Gabó válasza kisstomi5545 hozzászólására (») Dec 18, 2015 /
 
Valószínű, hogy a CH340 van rajta. Kell hozzá illesztőprogi, és megy.
(#) erdeidominik1999 hozzászólása Dec 19, 2015 /
 
Sziasztok! Azt tudom, hogy ha szöveget iratok lcd-re, serialra, stb. akkor f()-be kell raknom, hogy ne a ram-ot húzza, viszont ha write()-tal iratom, akkor nem hagyja. Mi a különbség a write, és a print között? Előre is köszi!
(#) kapu48 válasza erdeidominik1999 hozzászólására (») Dec 19, 2015 /
 
Flashban-ból csak 'const'-ot olvashatsz!
Változók csak a Ramban vannak, lehetnek.
(#) erdeidominik1999 válasza kapu48 hozzászólására (») Dec 19, 2015 /
 
Azt tudom hogy a változók csak ramban, de a fix szövegek, azokat print(f(""));-fel irassam, vagy simán write(""); ?
(#) kapu48 válasza erdeidominik1999 hozzászólására (») Dec 19, 2015 /
 
Értelem szerint a:
print(f("")); a flashból olvas. Nem foglal memóriát!
write("Szoveg"); előbb betölti a ramba "Szoveg" konstanst és onnan kerül kiírásra.

Ha spórolni akarsz a Rammal az előző verziót használod! Ennyi.
(#) k3gy3tl3n hozzászólása Dec 19, 2015 /
 
Sziasztok, kér db arduino nano-val (16MHz-en járnak) használok egy egy NRF24L01 modult, viszont nekem irtó lassúnak tűnik az adatátvitel. A vevőn ha soros monitoron nézem a kapott adatokat kb 2-4 csomag jön 1sec alatt. Az RF modulok 2Mbit/s-re vannak állítva az újraküldés pedig 0-ra. (fontosabb a friss adat mint hogy minden megjöjjön) Radiohed féle library-t használom.
Az adó:
  1. /* YourDuinoStarter Example: TRANSMIT nRF24L01 Joystick data to Pan Tilt Over Radio.
  2.    QUESTIONS? terry@yourduino.com
  3.  - WHAT IT DOES: Reads Joystick Analog Values on A0, A1 and transmits
  4.    them over a nRF24L01 Radio Link, using the Radiohead library.
  5.  - TODO! Send the Joystick push-down click to turn Laser on and off
  6.  - SEE the comments after "//" on each line below
  7.  - CONNECTIONS: nRF24L01 Modules See:
  8.  http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  9.    1 - GND
  10.    2 - VCC 3.3V !!! NOT 5V
  11.    3 - CE to Arduino pin 8
  12.    4 - CSN to Arduino pin 10
  13.    5 - SCK to Arduino pin 13
  14.    6 - MOSI to Arduino pin 11
  15.    7 - MISO to Arduino pin 12
  16.    8 - UNUSED
  17.  
  18.       -
  19.    Analog Joystick or two 10K potentiometers:
  20.    GND to Arduino GND
  21.    VCC to Arduino +5V
  22.    X Pot to Arduino A5
  23.    Y Pot to Arduino A4
  24.    Click Button to pin 4
  25.  
  26.    -V2.00 7/12/14  by Noah King
  27. */
  28.  
  29. /*-----( Import needed libraries )-----*/
  30. // SEE http://arduino-info.wikispaces.com/Arduino-Libraries  !!
  31. // NEED the RadioHead Library installed!
  32. #include <RHReliableDatagram.h>
  33. #include <RH_NRF24.h>
  34. #include <SPI.h>
  35.  
  36.  
  37. /*-----( Declare Constants and Pin Numbers )-----*/
  38. #define JoyStick_X_PIN     A5  //elore hatra
  39. #define JoyStick_Y_PIN     A4  //balra jobbra
  40. #define Offset_PIN         A6 //offset
  41. #define buttonPin          2
  42.  
  43. #define CLIENT_ADDRESS 5      // For Radio Link
  44. #define SERVER_ADDRESS 6
  45.  
  46.  
  47. // Create an instance of the radio driver
  48. RH_NRF24 RadioDriver;
  49.  
  50. // Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
  51. RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);// sets the driver to NRF24 and the client adress to 1
  52.  
  53. /*-----( Declare Variables )-----*/
  54. uint8_t joystick[4];  // 2 element array of unsigned 8-bit type, holding Joystick readings
  55.  
  56. // Predefine the message buffer here: Don't put this on the stack:
  57. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];    // Actually: 28 bytes (32 minus 4 byte header)
  58.  
  59. void setup()  /****** SETUP: RUNS ONCE ******/
  60. {
  61.   // begin serial to display on Serial Monitor. Set Serial Monitor to 115200
  62.   // See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
  63.   Serial.begin(115200);
  64.  
  65.   // NOTE: pinMode for Radio pins handled by RadioDriver
  66.   if (!RadioManager.init())   // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  67.     Serial.println("init failed");
  68.  
  69.   pinMode(buttonPin, INPUT);
  70. }
  71.  
  72.  
  73.  
  74. void loop() /****** LOOP: RUNS CONSTANTLY ******/
  75. {
  76.   //Read the joystick values, scale them to 8-bit type and store them in the joystick[] array.
  77.   Serial.println("Reading joystick values ");
  78.   // Take the value of Joystick voltages which are 0 to 1023 (10 bit), and convert them to 0 to 255 (8 bit)
  79.   joystick[0] = map(analogRead(JoyStick_X_PIN), 300, 723, 0, 255);
  80.   joystick[1] = map(analogRead(JoyStick_Y_PIN), 300, 723, 0, 255);
  81.   joystick[2] = map(analogRead(Offset_PIN), 300, 723, 0, 255);
  82.  
  83.   // check if the pushbutton is pressed.
  84.   // if it is, the buttonState is HIGH:
  85.   if (digitalRead(buttonPin) == HIGH)
  86.   {
  87.     joystick[3]=1;
  88.   }
  89.   else
  90.   {
  91.     joystick[3]=0;
  92.   }
  93.  
  94.   //Display the joystick values in the serial monitor.
  95.   Serial.print("x:");
  96.   Serial.print(joystick[0]);//elore hatra
  97.   Serial.print(" y:");
  98.   Serial.print(joystick[1]); //balra jobbra
  99.   Serial.print(" z:");
  100.   Serial.print(joystick[2]); //offset
  101.   Serial.print(" gomb:");
  102.   Serial.println(joystick[3]); //gomb
  103.  
  104.  // Serial.println("Sending Joystick data to nrf24_reliable_datagram_server");
  105.   //Send a message containing Joystick data to manager_server
  106.   if (RadioManager.sendtoWait(joystick, sizeof(joystick), SERVER_ADDRESS))
  107.   {
  108.     // Now wait for a reply from the server
  109.     uint8_t len = sizeof(buf);
  110.     uint8_t from;
  111.     if (1/*RadioManager.recvfromAckTimeout(buf, &len, 2000, &from)*/)
  112.     {
  113.     //  Serial.print("got reply from : 0x");
  114.     //  Serial.print(from, HEX);
  115.     //  Serial.print(": ");
  116.     //  Serial.println((char*)buf);
  117.     }
  118.     else
  119.     {
  120.      // Serial.println("No reply, is nrf24_reliable_datagram_server running?");
  121.     }
  122.   }
  123.   else
  124.    // Serial.println("sendtoWait failed");
  125.  
  126.   delay(25);  // Wait a bit before next transmission
  127. }


És a vevő kódja:
  1. /* YourDuinoStarter Example:RECEIVE nRF24L01 Joystick data to control Pan Tilt Servos Over Radio.
  2.    QUESTIONS? terry@yourduino.com
  3.  -WHAT IT DOES:
  4.   -Receives Joystick Analog Values over a nRF24L01 Radio Link, using the Radiohead library.
  5.   - Sends Joystick position to 2 servos, usually X,Y to pan-tilt arrangement
  6.   - TODO! Send the Joystick push-down click to turn Laser on and off
  7.  - SEE the comments after "//" on each line below
  8.  - CONNECTIONS: nRF24L01 Modules See:
  9.  http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  10.    1 - GND
  11.    2 - VCC 3.3V !!! NOT 5V
  12.    3 - CE to Arduino pin 8
  13.    4 - CSN to Arduino pin 10
  14.    5 - SCK to Arduino pin 13
  15.    6 - MOSI to Arduino pin 11
  16.    7 - MISO to Arduino pin 12
  17.    8 - UNUSED
  18.  
  19.  
  20.    -V2.00 7/12/14 by Noah King
  21. */
  22.  
  23. /*-----( Import needed libraries )-----*/
  24. // SEE http://arduino-info.wikispaces.com/Arduino-Libraries  !!
  25. // NEED the SoftwareServo library installed
  26. #include <SoftwareServo.h>  // Regular Servo library creates timer conflict!
  27.  
  28. // NEED the RadioHead Library installed!
  29. #include <RHReliableDatagram.h>
  30. #include <RH_NRF24.h>
  31.  
  32. #include <SPI.h>
  33.  
  34. /*-----( Declare Constants and Pin Numbers )-----*/
  35. #define CLIENT_ADDRESS     5
  36. #define SERVER_ADDRESS     6
  37.  
  38. #define ServoHorizontalPIN 3   //Pin Numbers
  39. #define ServoVerticalPIN   5
  40. #define LaserPIN           6
  41.  
  42. #define ServoMIN_H  0  // Don't go to very end of servo travel
  43. #define ServoMAX_H  160 // which may not be all the way from 0 to 180.
  44. #define ServoMIN_V  0  // Don't go to very end of servo travel
  45. #define ServoMAX_V  140 // which may not be all the way from 0 to 180.
  46.  
  47.  
  48. /*-----( Declare objects )-----*/
  49. //SoftwareServo HorizontalServo;
  50. //SoftwareServo VerticalServo;  // create servo objects to control servos
  51.  
  52. // Create an instance of the radio driver
  53. RH_NRF24 RadioDriver;
  54.  
  55. // Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
  56. RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
  57.  
  58. /*-----( Declare Variables )-----*/
  59. int HorizontalJoystickReceived; // Variable to store received Joystick values
  60. int HorizontalServoPosition;    // variable to store the servo position
  61.  
  62. int VerticalJoystickReceived;   // Variable to store received Joystick values
  63. int VerticalServoPosition;      // variable to store the servo position
  64.  
  65. uint8_t ReturnMessage[] = "JoyStick Data Received";  // 28 MAX
  66. // Predefine the message buffer here: Don't put this on the stack:
  67. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
  68. uint8_t tmp=0;
  69.  
  70. //--------------------------------( SETUP Runs ONCE )-----------------------------------------------------
  71. void setup()
  72. {
  73.   //pinMode(LaserPIN, OUTPUT);
  74.   //digitalWrite(LaserPIN, HIGH); // turn on Laser
  75.  
  76.   /*-----( Set up servos )-----*/
  77.   //HorizontalServo.attach(ServoHorizontalPIN);  // attaches the servo to the servo object
  78.   //VerticalServo.attach(ServoVerticalPIN);      // attaches the servo to the servo object
  79.  
  80.  
  81.   // begin serial to display on Serial Monitor. Set Serial Monitor to 115200
  82.   // See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
  83.   Serial.begin(115200);
  84.  
  85.   if (!RadioManager.init()){ // Initialize radio. If NOT "1" received, it failed.
  86.     Serial.println("init failed");
  87.   }
  88.   else
  89.   {
  90.     Serial.println("init ok");
  91.   }
  92.   // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  93. } // END Setup
  94.  
  95.  
  96.  
  97. //--------------------------------( LOOP runs continuously )-----------------------------------------------------
  98. void loop()
  99. {
  100.   if (RadioManager.available())
  101.   {
  102.  // Wait for a message addressed to us from the client
  103.     uint8_t len = sizeof(buf);
  104.     uint8_t from;
  105.     if (RadioManager.recvfromAck(buf, &len, &from))
  106.  //Serial Print the values of joystick
  107.     {
  108.       if(tmp<200){tmp++;}else{tmp=0;}
  109.       Serial.print("got request from : 0x");
  110.       Serial.print(from, HEX);
  111.       Serial.print(": X = ");
  112.       Serial.print(buf[0]);
  113.       Serial.print(" Y = ");
  114.       Serial.print(buf[1]);
  115.       Serial.print(" Z = ");
  116.       Serial.print(buf[2]);
  117.       Serial.print(" Gomb = ");
  118.       Serial.print(buf[3]);
  119.       Serial.print(" counter = ");
  120.       Serial.println(tmp);
  121.  
  122.       // Send a reply back to the originator client, check for error
  123.       //if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
  124.         //Serial.println(" sendtoWait failed");
  125.     }// end 'IF Received data Available
  126.   }// end 'IF RadioManager Available
  127.  
  128.   {
  129.    // SoftwareServo::refresh();//refreshes servo to keep them updating
  130.     //HorizontalJoystickReceived  = buf[1];  // Get the values received
  131.     //VerticalJoystickReceived    = buf[0];
  132.  
  133.     // scale it to use it with the servo (value between MIN and MAX)
  134.   //  HorizontalServoPosition  = map(HorizontalJoystickReceived, 0, 255, ServoMIN_H , ServoMAX_H);
  135.   //  VerticalServoPosition    = map(VerticalJoystickReceived,   0, 255, ServoMIN_V , ServoMAX_V);
  136.    // Serial.print("HorizontalServoPosition : ");
  137.    // Serial.print(HorizontalServoPosition);
  138.    // Serial.print("  VerticalServoPosition : ");
  139.    // Serial.println(VerticalServoPosition);
  140.     // tell servos to go to position
  141.    // HorizontalServo.write(HorizontalServoPosition);
  142.    // VerticalServo.write(VerticalServoPosition);
  143.    // delay(25);                      // wait for the servo to reach the position
  144.   }
  145. }// END Main LOOP

Bármilyen tippnek örülök. Az lehet hogy csak a soros kiíratás lassítja be az egész adás-vétel folyamatot?
(#) erdeidominik1999 válasza kapu48 hozzászólására (») Dec 19, 2015 /
 
Értem, köszi!
(#) kapu48 válasza k3gy3tl3n hozzászólására (») Dec 19, 2015 /
 
Biztos, hogy a terminál használat nagyon lassú!

Mi lenne, ha csak 4 – 5 LED-et villogtatnál if, else if utasításokkal?
(#) kapu48 válasza k3gy3tl3n hozzászólására (») Dec 20, 2015 /
 
A terminálra írások elhagyása biztosan felgyorsítja az adatátvitelt!

De ha nem kellenek a vételek visszaigazolása (ACK)?
Azzal is elérhetsz gyorsulást, ha a kevésbé biztonságos RHDatagram.h-t használod, RHReliableDatagram.h helyet.

Így nem vár az adó, visszaigazolásra a vevő oldaláról.
Meg spórolsz egy várakozást, csak vigyázni kel, hogy legyen ideje a vevőnek feldogozni a kapott utasítást a két adás között.
(#) kapu48 válasza k3gy3tl3n hozzászólására (») Dec 20, 2015 /
 
Próbáldki az ajánlott váltotatásokat!
Adó:
  1. /* YourDuinoStarter Example: TRANSMIT nRF24L01 Joystick data to Pan Tilt Over Radio.
  2.    QUESTIONS? terry@yourduino.com
  3. - WHAT IT DOES: Reads Joystick Analog Values on A0, A1 and transmits
  4.    them over a nRF24L01 Radio Link, using the Radiohead library.
  5. - TODO! Send the Joystick push-down click to turn Laser on and off
  6. - SEE the comments after "//" on each line below
  7. - CONNECTIONS: nRF24L01 Modules See:
  8. http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  9.    1 - GND
  10.    2 - VCC 3.3V !!! NOT 5V
  11.    3 - CE to Arduino pin 8
  12.    4 - CSN to Arduino pin 10
  13.    5 - SCK to Arduino pin 13
  14.    6 - MOSI to Arduino pin 11
  15.    7 - MISO to Arduino pin 12
  16.    8 - UNUSED
  17.  
  18.       -
  19.    Analog Joystick or two 10K potentiometers:
  20.    GND to Arduino GND
  21.    VCC to Arduino +5V
  22.    X Pot to Arduino A5
  23.    Y Pot to Arduino A4
  24.    Click Button to pin 4
  25.  
  26.    -V2.00 7/12/14  by Noah King
  27. */
  28.  
  29. /*-----( Import needed libraries )-----*/
  30. // SEE http://arduino-info.wikispaces.com/Arduino-Libraries  !!
  31. // NEED the RadioHead Library installed!
  32. //#include <RHReliableDatagram.h>
  33. #include <RHDatagram.h>
  34. #include <RH_NRF24.h>
  35. #include <SPI.h>
  36.  
  37.  
  38. /*-----( Declare Constants and Pin Numbers )-----*/
  39. #define JoyStick_X_PIN     A5  //elore hatra
  40. #define JoyStick_Y_PIN     A4  //balra jobbra
  41. #define Offset_PIN         A6 //offset
  42. #define buttonPin          2
  43.  
  44. #define CLIENT_ADDRESS 5      // For Radio Link
  45. #define SERVER_ADDRESS 6
  46.  
  47.  
  48. // Create an instance of the radio driver
  49. RH_NRF24 RadioDriver;
  50.  
  51. // Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
  52. //RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);// sets the driver to NRF24 and the client adress to 1
  53. RHDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);// sets the driver to NRF24 and the client adress to 1
  54.  
  55. /*-----( Declare Variables )-----*/
  56. uint8_t joystick[4];  // 2 element array of unsigned 8-bit type, holding Joystick readings
  57.  
  58. // Predefine the message buffer here: Don't put this on the stack:
  59. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];    // Actually: 28 bytes (32 minus 4 byte header)
  60.  
  61. void setup()  /****** SETUP: RUNS ONCE ******/
  62. {
  63.   // begin serial to display on Serial Monitor. Set Serial Monitor to 115200
  64.   // See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
  65.   Serial.begin(115200);
  66.  
  67.   // NOTE: pinMode for Radio pins handled by RadioDriver
  68.   if (!RadioManager.init())   // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  69.     Serial.println("init failed");
  70.  
  71.   pinMode(buttonPin, INPUT);
  72. }
  73.  
  74.  
  75.  
  76. void loop() /****** LOOP: RUNS CONSTANTLY ******/
  77. {
  78.   //Read the joystick values, scale them to 8-bit type and store them in the joystick[] array.
  79.   Serial.println("Reading joystick values ");
  80.   // Take the value of Joystick voltages which are 0 to 1023 (10 bit), and convert them to 0 to 255 (8 bit)
  81.   joystick[0] = map(analogRead(JoyStick_X_PIN), 300, 723, 0, 255);
  82.   joystick[1] = map(analogRead(JoyStick_Y_PIN), 300, 723, 0, 255);
  83.   joystick[2] = map(analogRead(Offset_PIN), 300, 723, 0, 255);
  84.  
  85.   // check if the pushbutton is pressed.
  86.   // if it is, the buttonState is HIGH:
  87.   if (digitalRead(buttonPin) == HIGH)
  88.   {
  89.     joystick[3]=1;
  90.   }
  91.   else
  92.   {
  93.     joystick[3]=0;
  94.   }
  95.  
  96.   //Display the joystick values in the serial monitor.
  97.   Serial.print("x:");
  98.   Serial.print(joystick[0]);//elore hatra
  99.   Serial.print(" y:");
  100.   Serial.print(joystick[1]); //balra jobbra
  101.   Serial.print(" z:");
  102.   Serial.print(joystick[2]); //offset
  103.   Serial.print(" gomb:");
  104.   Serial.println(joystick[3]); //gomb
  105.  
  106.  // Serial.println("Sending Joystick data to nrf24_reliable_datagram_server");
  107.   //Send a message containing Joystick data to manager_server
  108. //  if (RadioManager.sendtoWait(joystick, sizeof(joystick), SERVER_ADDRESS))
  109.   if (RadioManager.sendto(joystick, sizeof(joystick), SERVER_ADDRESS))  
  110.   {
  111.     // Now wait for a reply from the server
  112.     uint8_t len = sizeof(buf);
  113.     uint8_t from;
  114.     if (1/*RadioManager.recvfromAckTimeout(buf, &len, 2000, &from)*/)
  115.     {
  116.     //  Serial.print("got reply from : 0x");
  117.     //  Serial.print(from, HEX);
  118.     //  Serial.print(": ");
  119.     //  Serial.println((char*)buf);
  120.     }
  121.     else
  122.     {
  123.      // Serial.println("No reply, is nrf24_reliable_datagram_server running?");
  124.     }
  125.   }
  126.   else
  127.    // Serial.println("sendtoWait failed");
  128.  
  129.   delay(25);  // Wait a bit before next transmission
  130. }


Vevö:
  1. /* YourDuinoStarter Example:RECEIVE nRF24L01 Joystick data to control Pan Tilt Servos Over Radio.
  2.    QUESTIONS? terry@yourduino.com
  3. -WHAT IT DOES:
  4.   -Receives Joystick Analog Values over a nRF24L01 Radio Link, using the Radiohead library.
  5.   - Sends Joystick position to 2 servos, usually X,Y to pan-tilt arrangement
  6.   - TODO! Send the Joystick push-down click to turn Laser on and off
  7. - SEE the comments after "//" on each line below
  8. - CONNECTIONS: nRF24L01 Modules See:
  9. http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
  10.    1 - GND
  11.    2 - VCC 3.3V !!! NOT 5V
  12.    3 - CE to Arduino pin 8
  13.    4 - CSN to Arduino pin 10
  14.    5 - SCK to Arduino pin 13
  15.    6 - MOSI to Arduino pin 11
  16.    7 - MISO to Arduino pin 12
  17.    8 - UNUSED
  18.  
  19.  
  20.    -V2.00 7/12/14 by Noah King
  21. */
  22.  
  23. /*-----( Import needed libraries )-----*/
  24. // SEE http://arduino-info.wikispaces.com/Arduino-Libraries  !!
  25. // NEED the SoftwareServo library installed
  26. //#include <SoftwareServo.h>  // Regular Servo library creates timer conflict!
  27.  
  28. // NEED the RadioHead Library installed!
  29. //#include <RHReliableDatagram.h>
  30. #include <RHDatagram.h>
  31.  
  32. #include <RH_NRF24.h>
  33.  
  34. #include <SPI.h>
  35.  
  36. /*-----( Declare Constants and Pin Numbers )-----*/
  37. #define CLIENT_ADDRESS     5
  38. #define SERVER_ADDRESS     6
  39.  
  40. #define ServoHorizontalPIN 3   //Pin Numbers
  41. #define ServoVerticalPIN   5
  42. #define LaserPIN           6
  43.  
  44. #define ServoMIN_H  0  // Don't go to very end of servo travel
  45. #define ServoMAX_H  160 // which may not be all the way from 0 to 180.
  46. #define ServoMIN_V  0  // Don't go to very end of servo travel
  47. #define ServoMAX_V  140 // which may not be all the way from 0 to 180.
  48.  
  49.  
  50. /*-----( Declare objects )-----*/
  51. //SoftwareServo HorizontalServo;
  52. //SoftwareServo VerticalServo;  // create servo objects to control servos
  53.  
  54. // Create an instance of the radio driver
  55. RH_NRF24 RadioDriver;
  56.  
  57. // Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
  58. //RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
  59. RHDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
  60.  
  61. /*-----( Declare Variables )-----*/
  62. int HorizontalJoystickReceived; // Variable to store received Joystick values
  63. int HorizontalServoPosition;    // variable to store the servo position
  64.  
  65. int VerticalJoystickReceived;   // Variable to store received Joystick values
  66. int VerticalServoPosition;      // variable to store the servo position
  67.  
  68. uint8_t ReturnMessage[] = "JoyStick Data Received";  // 28 MAX
  69. // Predefine the message buffer here: Don't put this on the stack:
  70. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
  71. uint8_t tmp=0;
  72.  
  73. //--------------------------------( SETUP Runs ONCE )-----------------------------------------------------
  74. void setup()
  75. {
  76.   //pinMode(LaserPIN, OUTPUT);
  77.   //digitalWrite(LaserPIN, HIGH); // turn on Laser
  78.  
  79.   /*-----( Set up servos )-----*/
  80.   //HorizontalServo.attach(ServoHorizontalPIN);  // attaches the servo to the servo object
  81.   //VerticalServo.attach(ServoVerticalPIN);      // attaches the servo to the servo object
  82.  
  83.  
  84.   // begin serial to display on Serial Monitor. Set Serial Monitor to 115200
  85.   // See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
  86.   Serial.begin(115200);
  87.  
  88.   if (!RadioManager.init()){ // Initialize radio. If NOT "1" received, it failed.
  89.     Serial.println("init failed");
  90.   }
  91.   else
  92.   {
  93.     Serial.println("init ok");
  94.   }
  95.   // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  96. } // END Setup
  97.  
  98.  
  99.  
  100. //--------------------------------( LOOP runs continuously )-----------------------------------------------------
  101. void loop()
  102. {
  103.   if (RadioManager.available())
  104.   {
  105.  // Wait for a message addressed to us from the client
  106.     uint8_t len = sizeof(buf);
  107.     uint8_t from;
  108. //    if (RadioManager.recvfromAck(buf, &len, &from))
  109.     if (RadioManager.recvfrom(buf, &len, &from))    
  110.  //Serial Print the values of joystick
  111.     {
  112.       if(tmp<200){tmp++;}else{tmp=0;}
  113.       Serial.print("got request from : 0x");
  114.       Serial.print(from, HEX);
  115.       Serial.print(": X = ");
  116.       Serial.print(buf[0]);
  117.       Serial.print(" Y = ");
  118.       Serial.print(buf[1]);
  119.       Serial.print(" Z = ");
  120.       Serial.print(buf[2]);
  121.       Serial.print(" Gomb = ");
  122.       Serial.print(buf[3]);
  123.       Serial.print(" counter = ");
  124.       Serial.println(tmp);
  125.  
  126.       // Send a reply back to the originator client, check for error
  127.       //if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
  128.         //Serial.println(" sendtoWait failed");
  129.     }// end 'IF Received data Available
  130.   }// end 'IF RadioManager Available
  131.  
  132.   {
  133.    // SoftwareServo::refresh();//refreshes servo to keep them updating
  134.     //HorizontalJoystickReceived  = buf[1];  // Get the values received
  135.     //VerticalJoystickReceived    = buf[0];
  136.  
  137.     // scale it to use it with the servo (value between MIN and MAX)
  138.   //  HorizontalServoPosition  = map(HorizontalJoystickReceived, 0, 255, ServoMIN_H , ServoMAX_H);
  139.   //  VerticalServoPosition    = map(VerticalJoystickReceived,   0, 255, ServoMIN_V , ServoMAX_V);
  140.    // Serial.print("HorizontalServoPosition : ");
  141.    // Serial.print(HorizontalServoPosition);
  142.    // Serial.print("  VerticalServoPosition : ");
  143.    // Serial.println(VerticalServoPosition);
  144.     // tell servos to go to position
  145.    // HorizontalServo.write(HorizontalServoPosition);
  146.    // VerticalServo.write(VerticalServoPosition);
  147.    // delay(25);                      // wait for the servo to reach the position
  148.   }
  149. }// END Main LOOP
(#) ALI válasza atus1981 hozzászólására (») Dec 21, 2015 /
 
Ki próbáltam a ki íratást.
Rá jöttem mi a gond csak nem tudom hogy lehetne megoldani.
Ha benne van a setup-ban az analogReference(INTERNAL); akkor nem működik csak két gomb.
Ha ki veszem ezt belőle akkor megy az összes de ez kell a tized pontos hőmérséklet méréshez.
A hozzászólás módosítva: Dec 21, 2015
(#) Kovidivi válasza ALI hozzászólására (») Dec 21, 2015 /
 
Ha átállítod a belső referenciát 5V-ról 1.1V-ra, akkor nem kell újraszámolni a feszültség osztókon mérhető ADC értéket? Kapcsolástól függ a válasz.
(#) ALI válasza Kovidivi hozzászólására (») Dec 21, 2015 /
 
Újra kellene számolni de ki íratom a adc_key_in értékét, a nem működő gombokra értéket sem ír, olyan mintha meg se nyomnám.
A hozzászólás módosítva: Dec 21, 2015
(#) Kovidivi válasza ALI hozzászólására (») Dec 22, 2015 /
 
Gondolom a függvény nem kezeli ezt a különleges állapotot.
(#) andykaaa hozzászólása Dec 23, 2015 /
 
Ha kivállasztom a balső 1,1 v-os referenciát egy UNO-nál és 5,5 v-ot adok rá akkor az kiégeti ? Vagyis az analog kivezetés akkor csak max 1,1 v-ot bír el ?
(#) andykaaa válasza andykaaa hozzászólására (») Dec 23, 2015 /
 
nem 5,5 v-ot akartam irni, hanem 5 v-ot.
(#) icserny válasza andykaaa hozzászólására (») Dec 23, 2015 /
 
Értelmesen az ADC akkor csak 1.1 V-os vagy az alatti értéket tud feldolgozni, de "kiégetni" csak a VCC-t 0.5 V-tal meghaladó bemenőjel fogja, tehát az 5 V-os jel nem.
(#) kegyetlen19 hozzászólása Dec 23, 2015 /
 
Sziasztok.
Nemrégiben kezdtem el foglalkozni az Arduino-val. Az alapok már mennek. Vettem hozzá Led és Lcd kijelzőket. Kipróbálásukhóz a neten található „alap”kódokat akartam használni, (Link1, Link2, Link3, és az lcd-hez is hasonló alap kódokkal próbálkoztam) de mikor az 1.6.5. vagy a 1.6.6 –ban a kódot leellenőriztetem „Hiba a fordítás során” üzenetet kapom. Sajnos a hibás részt nem jelöli ki, így nem tudom mi lehet a hiba.
Kérnék egy kis segítséget a probléma megoldásához.
(#) andykaaa válasza icserny hozzászólására (») Dec 23, 2015 /
 
Idézet:
„Ha kivállasztom a balső 1,1 v-os referenciát egy UNO-nál és 5 v-ot adok rá akkor az kiégeti ? Vagyis az analog kivezetés akkor csak max 1,1 v-ot bír el ?”

Koszi a vallaszt. Nem akarlak alabecsulni de azert szuksegem lenne meg egy par megerositesre is. Nem akarok kiserletezni. Remelem megerted.
(#) GPeti1977 válasza andykaaa hozzászólására (») Dec 23, 2015 /
 
Csak az Aref lábra ne adj ilyenkor 5V ot, a többi analógra mehet. Amúgy is érdemes minden lábra ellenállást esetleg kondenzátort tenni aluláteresztő szűrőnek.
(#) kapu48 válasza kegyetlen19 hozzászólására (») Dec 23, 2015 /
 
Be kellene állítanod, ha látni akarod a teljes fordítási loggot!

Arduino:
File > Beállítások > Log mutatása – pipa.

pipa > Display line number. Hogy lásd a sorszámozást.
(#) kegyetlen19 válasza kapu48 hozzászólására (») Dec 23, 2015 /
 
Oké. Köszi. A link1 kód hibaüzenete:
C:\Users\Asztali\AppData\Local\Temp\arduino_fc4e855426c7eca1e0d3debefdb191cc\sketch_dec23a.ino:1:27: fatal error: TM1637Display.h: No such file or directory
#include <TM1637Display.h>
compilation terminated.
exit status 1
Hiba a fordítás során.

Akkor az 1 sor a hibás? Abban mi lehet a hiba?
(#) kapu48 válasza kegyetlen19 hozzászólására (») Dec 23, 2015 /
 
Mutatok egy egyszerű telepítési trükköt!

Az aktuális könyvtárba, most: TM1637Test.
Bemásolod az aktuális lib tartalmát, most:
TM1637Display.cpp, TM1637Display.h

Megváltoztatod a file elérési útvonal keresés módját:
Ahol szerepel: #include <TM1637Display.h>
Lecseréled: #include "TM1637Display.h" formára.
Ez esetben 2 helyen van: TM1637Display.cpp, TM1637Test.ino

Ezzel a módszerrel olvashatod és szerkesztheted minden használt alkalmazásodat.

(Persze ehhez az alapismereteknél már több tudás kel!)
De már így is sok trükköt elleshetsz.
(És még le is fordult hiba nélkül!)

Az TM1637Test.ino-t indítod!
A hozzászólás módosítva: Dec 23, 2015
Következő: »»   174 / 854
Bejelentkezés

Belépés

Hirdetés
XDT.hu
Az oldalon sütiket használunk a helyes működéshez. Bővebb információt az adatvédelmi szabályzatban olvashatsz. Megértettem