Recent Posts

Pages: [1] 2 3 ... 10
1

thanks a lot for the tips, after the implementation in the code the accuracy of the reading has increased a lot. now I will continue the code saving the data in arrays.
2
It is very unwise connecting +5v to 220 Ω to D0 and D1 as in you Fritzing drawing.







3
Information in your other post.
4
This is not Google. You are allowed to write sentences and paragraphs.
5
Making posts in more than 1 section of the forum is called "cross posting".  Cross posting is bad.

Please read the "how to use this forum-please read" stickies to see how to properly post code.
6
Project Guidance / Re: Accessing SRAM On Arduino ...
Last post by pay632006 - Today at 09:16 pm
The most common use of the .noinit and .initN sections seem to be:


Note that with the current IDE, you'll need to add the __attribute__ ((used)) to the .init functions as well.


Ok. thank you.
I am going to compare a "fingerprint" in my flash memory and reading data of SRAM in this  "iWantToRunBeforeSetup" function (before setup).

But as I understood it is not possible to call another function in this state (for example "pgm_read_word_near"), so how could I perform this checking before setup.
Should I change this "fingerprint" data location to somewhere else?
7



8
Programming Questions / Locating installed sketches
Last post by bob1148 - Today at 09:13 pm
After selecting add.zip, then to download, it shows  no valid library
9
Hello all.

So, what I'm trying to do seems like it should be simple, but I'm running into a number of odd behaviors that I'd like some help understanding. There are a number of issues I'm having, but I think it fundamentally appears to be a problem with getHostByName behaving in odd ways and so I'd like to just focus on that in this post.

My device is a WiDo (https://www.dfrobot.com/wiki/index.php/Wido-WIFI_IoT_Node_SKU:DFR0321).

Here is my setup routine:

Code: [Select]
void setup(void)
{
  Serial.begin(9600);
  while(!Serial);
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
 
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  } 

  while (! displayConnectionDetails()) {
    delay(1000);
  }

  uint32_t ip = 0;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  Serial.print("\nAs integer...");
  Serial.println(ip);
 
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); 
  int numReplies = cc3000.ping(ip, 5);
  Serial.print(numReplies); Serial.println(F(" replies"));
   
  cc3000.disconnect();
  Serial.println("Disconnected");
}


This works when the website I'm trying to reach (WEBSITE) is "www.google.com". Here is the output:

Initializing...

Attempting to connect to Feynman
Connected!
Request DHCP

IP Addr: 192.168.0.115
Netmask: 255.255.255.0
Gateway: 192.168.0.1
DHCPsrv: 192.168.0.1
DNSserv: 192.168.0.1
www.google.com -> 216.58.192.132
As integer...3627729028


Pinging 216.58.192.132...5 replies
Disconnected


Okay. So, notice how I saved away the integer representation of the IP address. If I use this integer (instead of calling getHostByName), then ping fails. Here is the new code:

Code: [Select]
void setup(void)
{
  Serial.begin(9600);
  while(!Serial);
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
 
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  } 

  while (! displayConnectionDetails()) {
    delay(1000);
  }

  uint32_t ip = 3627729028;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  // DONT CALL GETHOSTBYNAME
  //while (ip == 0) {
  //  if (! cc3000.getHostByName(WEBSITE, &ip)) {
  //    Serial.println(F("Couldn't resolve!"));
   // }
  //  delay(500);
  //}
  cc3000.printIPdotsRev(ip);
  Serial.print("\nAs integer...");
  Serial.println(ip);
 
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); 
  int numReplies = cc3000.ping(ip, 5);
  Serial.print(numReplies); Serial.println(F(" replies"));
   
  cc3000.disconnect();
  Serial.println("Disconnected");
}


This time, the ICMP fails ("0 replies"):

Initializing...

Attempting to connect to Feynman
Connected!
Request DHCP

IP Addr: 192.168.0.115
Netmask: 255.255.255.0
Gateway: 192.168.0.1
DHCPsrv: 192.168.0.1
DNSserv: 192.168.0.1
www.google.com -> 216.58.192.132
As integer...3627729028


Pinging 216.58.192.132...0 replies
Disconnected


The reason I'm doing this is that I seem to be unable to communicate with devices on my local network by IP. It seems as thought getHostByName is mandatory in this code, but I do not know why.

Am I missing something?

10
Robotics / Bluetooth receiver interfering...
Last post by qexox - Today at 09:12 pm
Hello. I'v built a toy car that has both an IR receiver (VS1838) and a bluetooth one (HC-05).
I want the car to be able operate with either form of control, the IR or the bluetooth.
So for example, if i use the bluetooth control, then at the same time, i want the IR receiver to not interfere.

Right now , with the code i'v written, the IR control doesn't work as long as the bluetooth module's TX pin is physically connected to the arduino's RX pin. This is due to the stop() function in the bluetooth part of the code (if (Serial.available() > 0){
  stops();).

I'm looking for way to keep that stop() function, without it interfering with the operation of the IR part of the code. Any suggestions?

I'm using an IR remote to operate the IR receiver, and a smartphone to operate the bluetooth receiver.

The part of the code with which i need help starts in the loop, all the way to the end of the bluetooth part in the loop. The code does other things as well, feel free to ignore them.

Also, i'm using arduino uno. Thank you in advance.


The full code:

#include <dht.h>
#include <IRremote.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>


//temperature sensor's variables
dht DHT;
#define DHT11_PIN 12
unsigned long previousMillis_temp = 0;  // will store last time temperature was updated
long interval_temp = 5000;  // interval at which to update temperature


//servo's variables
Servo myservo;
int increment = 20;
int pos = 90;
unsigned long previousMillis_servo = 0;
int interval_servo = 25;


// ultrasonic variables  
const int trigPin = 10;
const int echoPin = 9;
long duration;
int distance;
unsigned long previousMillis_distance = 0;
int interval_distance = 1000;


unsigned long currentMillis = 0;


//IR receiver's variables
const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

// Set the pins on the I2C chip used for LCD connections:
// address (of the I2C chip), en,rw,rs,d4,d5,d6,d7  
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7);



// forward and rear right motors
const int EN_A = 6;
const int IN_1 = 7;
const int IN_2 = 3;

// forward and rear left motors
const int IN_3 = 4;
const int IN_4 = 2;
const int EN_B = 5;

int pwm_speed = 200;


void setup() {
Serial.begin(9600);
myservo.attach(11);                 // attaches the servo on pin 11 to the servo object.
lcd.begin(16,2);                    // Initializes the interface to the LCD screen,
                                    // and specifies the dimensions (width and height) of the display.
lcd.setBacklightPin(3,POSITIVE);    // makes the P3 pin control the backlight of the LCD.
lcd.setBacklight(HIGH);             // makes the P3 pin go High, which turns on the NPN transistor.
      // This provides GND to the LED pin of the LCD as the other LED pin is already connected to Vcc
      // through the jumper, and this allows the LCD backlight to glow.
 
irrecv.enableIRIn();               // Infrared
irrecv.blink13(true);
 pinMode(EN_A, OUTPUT);
 pinMode(EN_B, OUTPUT);
 pinMode(IN_1, OUTPUT);
 pinMode(IN_2, OUTPUT);
 pinMode(IN_3, OUTPUT);
 pinMode(IN_4, OUTPUT);
 pinMode(trigPin, OUTPUT);        // Ultrasonic
 pinMode(echoPin, INPUT);

}

void loop() {

analogWrite(EN_A, pwm_speed);    
analogWrite(EN_B, pwm_speed);

if(distance <= 20 && pwm_speed >= 160) {
 stops();
 pwm_speed = 120;
}

else if (irrecv.decode(&results)){
 
  switch(results.value) {
  case 0xFF18E7:  // forward - keypad #2
   forward();
      break;

  case 0xFF4AB5:  // backward - keypad #8
   backward();
      break;

  case 0xFF10EF:  // Left - keypad #4
   left();
      break;

  case 0xFF5AA5:  // Right - keypad #6
   right();
      break;

  case 0xFF38C7:  // Stop - keypad #5
   stops();
      break;

  case 0xFFA857:  // increase speed - keypad (+)
   if(pwm_speed < 240)
    pwm_speed = pwm_speed + 40;
      break;
     
  case 0xFFE01F:  // decrease speed - keypad (-)
   if(pwm_speed > 160)
    pwm_speed = pwm_speed - 40;
      break;
 }  
irrecv.resume();
}



 if (Serial.available() > 0){
  stops();
 
 switch(Serial.read()) {
  case 'F':  // forward - keypad #2
   forward();
      break;

  case 'B':  // backward - keypad #8
   backward();
      break;

  case 'L':  // Left - keypad #4
   left();
      break;

  case 'R':  // Right - keypad #6
   right();
      break;
 }
}


// to make sure that the trigpin is clear of any signal we set it to LOW for 2(us).
digitalWrite(trigPin,LOW);  
delayMicroseconds(2);
               
digitalWrite(trigPin,HIGH);    // telling the Trig pin of the ultrasonic sensor to send a signal.
delayMicroseconds(10);
digitalWrite(trigPin,LOW);     // telling the Trig pin of the ultrasonic to stop sending the signal.

duration = pulseIn(echoPin,HIGH);
distance = duration*0.0343/2;
 
 
currentMillis = millis();
ultrasonicDistance();
servoSweep();
temperature();
}



//functions for controling the movement of the car

void forward() {
 digitalWrite(IN_1, HIGH);
 digitalWrite(IN_2, LOW);
 digitalWrite(IN_3, HIGH);
 digitalWrite(IN_4, LOW);
}

void backward() {
 digitalWrite(IN_1, LOW);
 digitalWrite(IN_2, HIGH);
 digitalWrite(IN_3, LOW);
 digitalWrite(IN_4, HIGH);
}

void left() {
 digitalWrite(IN_1, HIGH);
 digitalWrite(IN_2, LOW);
}

void right() {
 digitalWrite(IN_3, HIGH);
 digitalWrite(IN_4, LOW);
}

void stops() {
 digitalWrite(IN_1, LOW);
 digitalWrite(IN_2, LOW);
 digitalWrite(IN_3, LOW);
 digitalWrite(IN_4, LOW);
}

void servoSweep() {
 if(currentMillis - previousMillis_servo >= interval_servo){
   previousMillis_servo = currentMillis;
   pos += increment;
   myservo.write(pos);
   if((pos >= 100) || (pos <= 30))
     increment = -increment;
 }
}

void temperature() {
 if(currentMillis - previousMillis_temp >= interval_temp) {
  previousMillis_temp = currentMillis;
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,1);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
 }
}

void ultrasonicDistance() {
 if(currentMillis - previousMillis_distance >= interval_distance) {
   previousMillis_distance = currentMillis;
   
 lcd.setCursor(0,0);  // lcd.setCursor(col, row)
// Sets the location at which subsequent text written to the LCD will be displayed.
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" Cm");
 }
}
Pages: [1] 2 3 ... 10