Pages: [1] 2 3 ... 10
 1 
 on: Today at 02:55:40 pm 
Started by max10891 - Last post by ibbba
Interessante questo topic,in effetti mi è sempre parso una grossa dimenticanza o trascuratezza il non implementare un sistema failsafe nella strausata routine Wire.
Stavo dando uno sguardo al codice,due cose:
-il timeout dovrebbe essere applicato a tutti i while presenti nella libreria
-in caso di timeout occorso bisognerebbe verificare che la libreria continuasse a lavorare per interrogare altri eventuali devices presenti sul bus e magari lo segnalasse in qualche modo,tramite un codice ritornato o altro..

Si potrebbe pensare di creare una libreria parallela con implementate queste migliorie in modo che possa essere facilmente inserita nel codice

 2 
 on: Today at 02:55:10 pm 
Started by Mat13 - Last post by PaulRB
This is the best match I can find for the data sheet:

http://futurlec.com/LED/7SOG40011AEG.shtml

The forward voltage depends on the colour but most are quoted as 2.1V. There are 5 leds shown for each segment (except the dp - be careful with that!) which would make the total 10.5V for the segments (but only 2.1V for the dp).

 3 
 on: Today at 02:54:31 pm 
Started by adilmalik - Last post by ardiri
No, they don't.
The first one is correct (for positive integers). The second one isn't even close.

woops smiley forgot the multiply - need more coffee.

Code:
x = ((x + 7) / 8) * 8;

 4 
 on: Today at 02:51:32 pm 
Started by growqx - Last post by growqx
Hello!
I'm not sure if this question is suited for this forum or the Project Guidance one, anyway here goes.

Basically I'm making an Android app, which communicates with Arduino by using the popular HC-05 Bluetooth module. Although I'm able to send data back and forth, the quality of the data is worse than I would like, usually only ~30-60% of the data is usable.

For example, if I send "12345" with the Arduino, on the Android end the order of the characters often goes bad, and I might receive "23451" or something similar.  However, the problem doesn't last too long and generally the message goes in the correct order.
On the other hand, sending "abcde" from the Android device to the Arduino is much more prone to errors. Not only it suffers from the message getting out of order, but it also prints out gibberish characters for a few message cycles before going back to normal.

I attached the code from both devices below.

Arduino code:
Quote
#include <SoftwareSerial.h>// import the serial library

SoftwareSerial mSerial(10, 11); // RX, TX


char bytes[6];
int index = 0;
boolean reading = false;

void setup() {
  mSerial.begin(4800);
  Serial.begin(9600);
  Serial.println("Startup completed");
}

void loop() {

  read();
  mSerial.write(",12345");
  delay(200);
}

void read() {
  if (!reading && mSerial.read() == ',') {
    reading = true;
  }
  if (read) {
    int i = mSerial.available();
    while (i > 0 && index < 5) {
      bytes[index] = mSerial.read();
      i--;
      index++;
    }
    if (index >= 4) {
      for (int j = 0; j < 5; j++) {
        Serial.print(bytes[j]);
      }
      Serial.println();
      index = 0;
      reading = false;
    }
  }
}

Android code:
Quote
/* Imports */

@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
public class Main extends Activity {

   private Reader ReadThread = null;

   private String name = null;
   private String address = null;

   BluetoothAdapter adapter = null;
   BluetoothSocket socket = null;
   BluetoothDevice device = null;
   BluetoothServerSocket ServerSocket = null;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_list_item);
      System.out.println("OnCreate started");
      bluetooth();
   }

   protected void onDestroy() {
      super.onDestroy();

      try {
         socket.close();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

   }

   public void bluetooth() {

      Boolean foundit = false;
      adapter = BluetoothAdapter.getDefaultAdapter();

      if (!adapter.isEnabled()) {
         Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
         startActivityForResult(turnOn, 0);
      }

      Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
      // If there are paired devices
      if (pairedDevices.size() > 0) {
         // Loop through paired devices
         for (BluetoothDevice deviceTmp : pairedDevices) {
            if (deviceTmp.getName().toString()
                  .equalsIgnoreCase("ARDUINOBT")) {
               name = deviceTmp.getName();
               address = deviceTmp.getAddress();
               device = deviceTmp;
               Toast.makeText(getApplicationContext(),
                     "Name: " + name + ", address:" + address,
                     Toast.LENGTH_SHORT).show();
               foundit = true;
            }
            break;
         }
         if (!foundit) {
            Toast.makeText(getApplicationContext(), "BT device not found",
                  Toast.LENGTH_SHORT).show();
            ;
         }
      } else {
         Toast.makeText(getApplicationContext(), "No paired devices",
               Toast.LENGTH_SHORT).show();

      }

      UUID mDeviceUUID = UUID
            .fromString("00001101-0000-1000-8000-00805F9B34FB");
      try {
         adapter.cancelDiscovery();
         socket = device
               .createInsecureRfcommSocketToServiceRecord(mDeviceUUID);

      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

      try {
         socket.connect();

      } catch (IOException connectException) {
         // Unable to connect; close the socket and get out

         try {
            socket.close();
         } catch (IOException closeException) {
         }
      }

      System.out.println("Bluetooth initialized!");

      ReadThread = new Reader();
      while (true) {
         write(",abcde");
         try {
            Thread.sleep(200);
         } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }

      }
   }

   /** Will cancel an in-progress connection, and close the socket */
   public void cancel() {
      try {
         socket.close();
      } catch (IOException e) {
      }
   }

   public void write(String msg) {

      msg = msg;

      try {
         socket.getOutputStream().write(msg.getBytes());
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      System.out.print("SENT: ");
      System.out.println(msg);

   }

   private class Reader implements Runnable {
      private Thread t;

      public Reader() {
         t = new Thread(this, "Input Thread");
         t.start();

      }

      @Override
      public void run() {
         InputStream mmInStream = null;
         byte[] buffer = new byte[5];
         int index = 0;
         boolean read = false;
         try {
            mmInStream = socket.getInputStream();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         while (true) {

            // Keep listening to the InputStream until an exception occurs
            try {
               
               if ((char) mmInStream.read() == ',') {
                  read = true;
               }
               if (read) {
                  int i = mmInStream.available();
                  while (i > 0 && index < 5) {
                     buffer[index] = (byte) mmInStream.read();
                     i--;
                     index++;
                  }
                  if (index >= 4) {
                     // String strInput = new String(buffer, 0, 5);
                     String strInput = "";
                     for (int j = 0; j < buffer.length; j++) {
                        strInput = strInput + (char) buffer[j];
                     }
                     System.out.print("READ: ");

                     System.out.println(strInput);

                     index = 0;
                     read = false;
                  }
               }

            } catch (IOException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
            }

            try {
               Thread.sleep(200);
            } catch (InterruptedException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
         }
      }
   }
}

As you can see, I inserted delay() and Thread.sleep() in both Arduino and Android code to increase the stability of the connection. At first I tried 10ms, but that resulted in horrible message quality, therefore I increased it to the largest acceptable delay/sleep time (if I increase it more, the communication will be too slow for my intended purpose, rendering it useless).
Also, I add a comma to the beginning of each message as it works as a start bit - the bytes of the message are stored in the buffer array only after a comma has been received and read. This did seem to increase the quality of the communication a little bit, however, it didn't change much and the results were similar without using anything like this.

Lastly, I have set the HC-05 module to 4800 baud/s, because it seemed to be more stable at lower speeds, in fact, higher baud rates delivered gibberish bytes. Also, the module now is working without a parity or a stop bit, which can be enabled in its settings (AT mode). Should they be enabled or using commas as an improvised start/stop bit is just as good?

Hopefully someone can help out, thanks!

 5 
 on: Today at 02:49:28 pm 
Started by Pelodiulo - Last post by pelletta
@Palletta
....
Puoi consigliarmi dei LED  da 1 W che non costino un occhio della testa?

No, così impari a scrivere bene i nickname smiley-twist

 6 
 on: Today at 02:49:20 pm 
Started by mickmiller - Last post by michinyon
Quote
asks for an array with one element, which is no different than a plain int,

It creates a storage location which contains one int  and then it creates another variable which is a pointer to that location.    Not the same at all.

 7 
 on: Today at 02:48:37 pm 
Started by elektron_ - Last post by sschultewolter
Steht da Arduino oder nur duino?

Wenn 2. eintrifft, handelt es sich um keine Produktfälschung sondern um einen legitimer Nachbau.

Sehe ich das richtig, kein Spannungsregler? Das wäre nicht mal verkehrt für mich. Lediglich die Beschriftung sieht Minderwertig aus, was aber nicht beeinträchtigt.

 8 
 on: Today at 02:47:30 pm 
Started by virtualbench - Last post by nid69ita
Ti invitiamo a presentarti (dicci quali conoscenze hai di elettronica e di programmazione) qui: Presentazioni
e a leggere il regolamento: Regolamento
- qui una serie di schede by xxxPighi per i collegamenti elettronici vari: ABC - Arduino Basic Connections
- qui le pinout delle varie schede by xxxPighi: Pinout
- qui una serie di link generali utili: Link Utili

 9 
 on: Today at 02:47:18 pm 
Started by vanschagen - Last post by CrossRoads
Use the random( ) command to pick a number from 0 to 63, then write the appropriate bit into one of 8 registers that represents the state of the 64 LEDs the MAx7219 controls.

 10 
 on: Today at 02:47:05 pm 
Started by SURESH952 - Last post by raschemmel
Quote
DEFINE "FLASH "  

All of the answers you have been given pertain to loading a bootloader not uploading sketches.
AGAIN i ASK YOU ,
WHAT DO YOU MEAN BY "FLASH" ?
Obviously , to everyone who responded to your question it means "flashing the bootloader", because you don't use ICSP to upload sketches to an arduino UNO.
DO YOU MEAN UPLOAD SKETCHES  ?(I'M SCREAMING BECAUSE THAT IS YOUR PREFERRED METHOD OF COMMUNICATION)

OR

DO YOU MEAN FLASH THE BOOTLOADER ?

If you are new to the forum it is quite possible you think FLASHING is uploading the sketch because it is stored in non-volatile
ram, but here on the forum , if we are talking about upload (or downloading , however you call it) a sketch , we never call it
FLASHING because we reserve that term for loading a bootloader or loading a sketch to an ATtiny85 via ICSP using  "Arduino as ISP" Programming Mode and  the ArduinoISP sketch loaded in an Arduino UNO.

So to answer your question, if your students use the arduino UNO, the bootloader is already installed and all they need is a computer with a USB port and Windows or Mac version of the IDE. and the USB cable that I think comes with the UNO.
That's all they need to load programs. Try explaining your objective WITHOUT using the word FLASH.

Pages: [1] 2 3 ... 10