Recent Posts

Pages: 1 ... 8 9 [10]
91
Programming Questions / while (function == true ) inst...
Last post by K0ld - Today at 01:52 am
Hello! I am making a line follower and I would like some help.
I already made some functions, such as turnRight and turnLeft.
So, I want my robot to make a 90° degree turn using something like this:
   
  if the left sensor detects black and the right sensor detects white, turn left.
         while turning left, as long as the right sensor doesn't detect black, keep turning left.

               
I know "while" is meant to be used with an expression [e.g. while (something == true) ]. But I want to use it with a function instead, as "
Code: [Select]
while (function == true). Something like: 
Code: [Select]
while (turnLeft == true). So, would that work?

     
Code: [Select]
// Lv = left sensor value,    Rv = right sensor value
     // 1 = black       0 = white
   
        if ((Lv == 1) && (Rv == 0))
  {
    turnLeft(255);
//255 is the turning speed
    while (turnLeft == true)
    {
      if (Rv==!1)
    {
      turnLeft;
    }
   }
  }]
92
Displays / Re: Nextion 7" display distort...
Last post by Gra55y - Today at 01:45 am


180x180 pixels on my monitor is looks similar to 180x195 pixels on the Nextion.
93
Microcontrollers / Re: ATMEGA2560 Standalone I2C ...
Last post by 3Dgeo - Today at 01:39 am
Same Programm on the ATMEGA2560 standalone PCB, delivers SCL at 0.7/2V. SCL/SDA are not connected to anything else on the pcb, except the breakout Pins.
I2C is "Open collector", this means that Master and Slaves only pulls SCL and SDA to ground when communicating, so pull up resistors are required.

Usually if I don't have pullups when I'm doing prototyping I just add something like 0.9" OLED display or other I2C device - they usually have pullups on them (check with multimeter) and run "I2C scanner" script.
94
Hardware / Re: SERVO ARDUINO - COME TENER...
Last post by Maurotec - Today at 01:38 am
Quote
ma non è alla nostra portata oggettivamente...
Io non saprei neanche da dove partire... :)
Se usassi un arduino su breadboard potrei spiegarti come fare, ma usando arduino standard credo non sia possibile senza fare modifiche hardware. In sostanza serve un condensatore da 10uf (C) e una resistenza da 22kohm (R). C va connesso tra +5V e pin reset del ATmega328, la R va connessa allo stesso pin, l'altro capo di R va al pin RESET del convertitore Serial.

Con questi valori ritardi il reset di circa 100ms. Ora un pin di arduino viene connesso al pin RESET del convertitore Serial, questo pin sente il comando di reset all'instante, il codice lo rileva, salva i valori e resta in attesa senza fare nulla (un delay 1000), quando C si scarica è la tensione sul pin reset del 328 scende sotto 3.5V la MCU si resetta.

Comunque prima di affrontare questa modifica conviene creare lo stesso meccanismo ma attivabile manualmente attraverso un pulsante da premere prima di scrivere un nuovo sketch.

Ciao.   
95
All c++ object names evaluate to pointers, just like for arrays.
You were doing well, but went off the beam with that one. First, the name of an object that's an instance of a class can be defined to evaluate to just about anything using operator overloading, for example:
Code: [Select]
operator uint32_t() const { return internalVariable; }
Even if that's not the case, calling a function with an object name as an argument (without specifying it as a pointer or reference in the function's defintion) will use Call by Value. Meaning a copy of the object will be placed on the stack before the function is called. If the class has a defined Copy Constructor, it will be used for this. Otherwise the default copy constructor will be used, perhaps with unexpected results.
96
I have been working on a program to control a DirecTV STB via an IR blaster as my first Arduino project. I have successfully set up the hardware and multiple sketch's but need help combining both Switch..case and If statements into one. I need the sketch to allow multiple numerical digit inputs for changing the channel(0-9). Commands are sent via Serial Monitor. I have successfully achieved this using the following sketch:
Code: [Select]
#include <IRLibAll.h>

IRsend irsender;
byte byteRead;

void(* resetFunc) (void) = 0;

void setup() {
  Serial.begin(9600);
  Serial.println(" DirecTV  IR Blaster ");
  Serial.println("Input a Command");
}

void loop() {
  if (Serial.available()) {
    byteRead = Serial.read();
    Serial.println(byteRead);

  }
}

void processResponse() {
  switch (byteRead) {     
   case 'o':
      Serial.println("Power");
       irsender.send(DIRECTV,0xc105, 16);
      delay(40);
      Serial.println("Command Sent");
      return;
      break;
    case '0':
      Serial.println("0");
      irsender.send(DIRECTV,0xc116, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '1':
      Serial.println("1");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '2':
      Serial.println("2");
      irsender.send(DIRECTV,0xc022, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '3':
      Serial.println("3");
      irsender.send(DIRECTV,0xc033, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '4':
      Serial.println("4");
      irsender.send(DIRECTV,0xc043, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '5':
      Serial.println("5");
       irsender.send(DIRECTV,0xc054, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '6':
      Serial.println("6");
       irsender.send(DIRECTV,0xc065, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '7':
      Serial.println("7");
       irsender.send(DIRECTV,0xc076, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '8':
      Serial.println("8");
       irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
   case '9':
      Serial.println("9");
       irsender.send(DIRECTV,0xc097, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
      default:
      break;
  }
}


However the switch statement does not allow enough cases for all the buttons. The button identifiers begin with DTV to differentiate them from the ones for the TV i will be adding. The following sketch is where the issue lies:

Code: [Select]
#include <IRLibAll.h>

IRsend irsender;
String input;
byte inputbyte;
char inputchar;
void(* resetFunc) (void) = 0;

void setup() {
  Serial.begin(9600);
    Serial.println("Ready!");
}
void loop() {
  if (Serial.available()) {
    Serial.println("ok");
    input=Serial.readString();
    inputchar=input.charAt(0);
    inputbyte = (byte)inputchar;
    Serial.println(inputbyte);
    numbers();
    power();
  }
}
void numbers() {
switch (inputbyte) {
    case '0':
      Serial.println("0");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '1':
      Serial.println("1");
      irsender.send(DIRECTV,0xc011, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '2':
      Serial.println("2");
      irsender.send(DIRECTV,0xc022, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '3':
      Serial.println("3");
      irsender.send(DIRECTV,0xc033, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '4':
      Serial.println("4");
      irsender.send(DIRECTV,0xc043, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '5':
      Serial.println("5");
       irsender.send(DIRECTV,0xc054, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '6':
      Serial.println("6");
       irsender.send(DIRECTV,0xc065, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '7':
      Serial.println("7");
       irsender.send(DIRECTV,0xc076, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case '8':
      Serial.println("8");
       irsender.send(DIRECTV,0xc086, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
   case '9':
      Serial.println("9");
       irsender.send(DIRECTV,0xc097, 16);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
      default:
      break;
}
}
 void power() {
      if (input == "DTVPOWER") {
      irsender.send(DIRECTV,0xc105, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        CHUP();
      }
  }
  void CHUP(){
    if (input == "DTVCHUP") {
     irsender.send(DIRECTV,0xc0da, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        CHDOWN();
  }
  }
  void CHDOWN() {
    if (input == "DTVCHDOWN") {
      irsender.send(DIRECTV,0xc0eb, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        MENU();
  }
  }
  void MENU() {
    if (input == "DTVMENU") {
      irsender.send(DIRECTV,0xc20a, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        EXIT();
  }
  }
  void EXIT() {
     if (input == "DTVEXIT") {
      irsender.send(DIRECTV,0xc26F, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        GUIDE();
  }
  }
 void GUIDE() {
     if (input == "DTVGUIDE") {
      irsender.send(DIRECTV,0xc280, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
        INFO();
  }
  }
  void INFO() {
    if (input == "DTVINFO") {
      irsender.send(DIRECTV,0xc2e5, 16);
      delay(40);
      Serial.println("Sent.");
    }
    else {
      ENTER();
    }
  }
 
  void ENTER() {
     if (input == "DTVENTER") {
      irsender.send(DIRECTV,0xc138, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
       PREVIOUS();
  }
  }
   void PREVIOUS() {
     if (input == "DTVPREVIOUS") {
      irsender.send(DIRECTV,0xc0fc, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
     delay(40);
      Serial.println("Sent.");
    }
      else {
       DASH();
  }
  }
   void DASH() {
     if (input == "DTVDASH") {
      irsender.send(DIRECTV,0xc127, 16);
      delay(40);
      Serial.println("Sent.");
    }
      else {
       Serial.println("Sorry, Comamnd not found!");
    }
  }

Which works beside not being able to input multiple numerical digits at once as it only accepts the first entered. I feel the issue lies in converting the inputted string into bytes but can not figure out a fix.  i know strings are not ideal for this job but am not sure of another easy way to specifically identify with enough combinations.  Any guidance would be appreciated! I know the code can also be simplified/improved, in which i will work on once it works. Thank you for your help and patients!

97
Hardware / EV bistabile con L293E
Last post by meluino - Today at 01:26 am
Buonasera a tutti.

Ho utilizzato in passato un L293E associato ad Arduino per comandare dei DC motors con cambio di direzione, la configurazione è come quella presente nel DATASHEET, con i diodi a protezione delle extratensioni.
Non ho avuto nessun problema a realizzare il circuito anche perché tutto era alimentato a 5V, motori compresi.

Ora vorrei utilizzare lo stesso schema per comandare delle elettrovalvole bistabili e il "problema" qui sta nel fatto che le EV hanno una tensione di lavoro di 24V.

Ho letto, sempre nel datasheet, che l'L293E supporta tensioni di alimentazione sino ad un massimo di 36V, quindi i miei 24V vanno (dovrebbero) andare più che bene. La tensione sui pin di abilitazione, con una Vss come quella che voglio fornire va da 2,3V a 7V, quindi anche qui credo che non ci siano problemi di interfaccia con le uscite di Arduino.

La mia domanda in conclusione è, le uscite del L293E, una volta abilitate sono pari a Vss? Ovvero, posso collegare la mia EV che lavora a 24V direttamente all'integrato o devo accoppiarle in qualche altro modo?

Grazie

Meluino



98
Microcontrollers / Re: ATmega32U4 to upload code ...
Last post by 3Dgeo - Today at 01:25 am
Hello,

I'm probably not the smartest person here to reply, but I just had to ask:
Why? Why ATmega32U4 and ATmega2560? Why 2 MCUs? Why not regular FTDI and ATmega2560?
Why not SAMD or STM32?  :o
99
Software / Re: Consulta comunicación seri...
Last post by surbyte - Today at 01:20 am
Y el que falta que?

1 para Monito Serie
1 para BT
1 para 485
te queda 1

Mega Serial
100
Perry,

I suspect your confusion is, in part, due to the somewhat inconsistent way c/c++ addresses data.  For all simple, integral data types (char, int, long, bool, etc.), the variable name, when used by itself, evaluates to the VALUE of the data:

int x = 10;      // x has the value 10

Serial.print(x);    // x has the value 10, so this prints "10"
Serial.print(&x);  // &x is the memory ADDRESS of x, Serial.print receives a pointer to x

But for some complex types, arrays in particular, the variable name evaluates to a POINTER to the data, which is the memory ADDRESS of the first element of the array.

char x[10] = "abcd";  // x is a 5-element array of char
Serial.print(x);          // x here evaluates to the ADDRESS of x[0].  i.e. - Serial.print receives a pointer
Serial.print(&x[0]);   // This is exactly equivalent to the previous line, as it explicitly gets the address of x[0]

All c++ object names evaluate to pointers, just like for arrays.

Then there's the confusion of references, which also use the "&" symbol, but for a slightly different purpose...

So, in deciding whether or not you need an & (AddressOf operator), look at the type of the data.  If it's a simple type, and you want the value, no ampersand.  Otherwise, add the ampersand to get a pointer to the data instead.  For complex types, you most often only need the & if you want to get a pointer to one element of an array, in which case you need to also specific WHICH element, by providing [n] indexing.

Regards,
Ray L.
Pages: 1 ... 8 9 [10]