Arduino Uno et la saisie de texte

Bonjour a toutes et a tous enfin bonsoir :slight_smile:

Je viens a vous car j'ai cherchertoute la soirée une solution mais en vain :cry:

Je desire pouvoir en appuyant sur un bouton, faire en sorte que mon arduino saisis a l'ecran un texte deja enregistré :slight_smile:

C'est a dire.

En ecrivant mon programme j'aimerai lui faire comprendre que si le bouton est enfoncé alors il va afficher le texte pre enregistré a l'ecran et si le bouton n'est pas enfoncé alors il fait rien.

Ce qui me permettrai entre autre, pour la geek attitude ^^, de faire en sorte que si mon arduino est connecté sur mon ordi, qu'il puisse faire croire a mon ordi que je tape le mot de passe alors que c'est l'arduino qui le saisie tout seul.

J'ai essayé un serial.print mais ca affiche uniquement dans le monitor dispo dans le programme d'Arduino et pas dans le champ texte que je desirerai.

Merci de votre aide :slight_smile:

Je ne suis pas rentré dans les détails mais on dirait que ce lien est sympa ...

je ne sais pas trop comment m'y prendre :cry:

Voici le code proposé que je pourrai adapté en isolant la ligne qui affiche le texte brut :slight_smile:

/**
* VirtualUsbKeyboard
*
* Enumerates itself as a HID (Human Interface Device) to a host
* computer using a USB shield. The Arduino then appears to the host to
* be a USB keyboard and keypress events can be sent on demand.
*
* This example watches the state of 6 push buttons and when a button
* is pressed it sends a matching keypress event to the host.
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. http://www.gnu.org/licenses/
*
* www.practicalarduino.com/projects/easy/virtual-usb-keyboard
*/

// Requires the use of the "UsbKeyboard" library available from
// http://code.rancidbacon.com/ProjectLogArduinoUSB
#include "UsbKeyboard.h"

// Define the inputs to use for buttons
#define BUTTON_A 6
#define BUTTON_B 7
#define BUTTON_C 8
#define BUTTON_D 9
#define BUTTON_MSG 10
#define BUTTON_ENTER 11

// Use the on-board LED as an activity display
int ledPin = 13;

/**
* Configure button inputs and set up the USB connection to the host
*/
void setup()
{
  // Set up the activity display LED
  pinMode (ledPin, OUTPUT);
  digitalWrite (ledPin, HIGH);

  // Set the button pins to inputs
  pinMode (BUTTON_A, INPUT);
  pinMode (BUTTON_B, INPUT);
  pinMode (BUTTON_C, INPUT);
  pinMode (BUTTON_D, INPUT);
  pinMode (BUTTON_MSG, INPUT);
  pinMode (BUTTON_ENTER, INPUT);

  // Enable the CPU's internal 20k pull-up resistors on the button
  // inputs so they default to a "high" state
  digitalWrite (BUTTON_A, HIGH);
  digitalWrite (BUTTON_B, HIGH);
  digitalWrite (BUTTON_C, HIGH);
  digitalWrite (BUTTON_D, HIGH);
  digitalWrite (BUTTON_MSG, HIGH);
  digitalWrite (BUTTON_ENTER, HIGH);

  // Disable timer0 since it can mess with the USB timing. Note that
  // this means some functions such as delay() will no longer work.
  TIMSK0&=!(1<<TOIE0);

  // Clear interrupts while performing time-critical operations
  cli();

  // Force re-enumeration so the host will detect us
  usbDeviceDisconnect();
  delayMs(250);
  usbDeviceConnect();

  // Set interrupts again
  sei();
}


/**
* Main program loop. Scan for keypresses and send a matching keypress
* event to the host
* FIXME: currently repeats as fast as it can. Add transition detection
*/
void loop()
{
  UsbKeyboard.update();

  if (digitalRead(BUTTON_A) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_A);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

  if (digitalRead(BUTTON_B) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_B);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

  if (digitalRead(BUTTON_C) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_C);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

  if (digitalRead(BUTTON_D) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_D);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

  if (digitalRead(BUTTON_MSG) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_H, MOD_SHIFT_LEFT);
    UsbKeyboard.sendKeyStroke(KEY_E);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_O);
    UsbKeyboard.sendKeyStroke(KEY_SPACE);
    UsbKeyboard.sendKeyStroke(KEY_W, MOD_SHIFT_LEFT);
    UsbKeyboard.sendKeyStroke(KEY_O);
    UsbKeyboard.sendKeyStroke(KEY_R);
    UsbKeyboard.sendKeyStroke(KEY_L);
    UsbKeyboard.sendKeyStroke(KEY_D);
    UsbKeyboard.sendKeyStroke(KEY_ENTER);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

  if (digitalRead(BUTTON_ENTER) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_ENTER);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }
}


/**
* Define our own delay function so that we don't have to rely on
* operation of timer0, the interrupt used by the internal delay()
*/
void delayMs(unsigned int ms)
{
  for (int i = 0; i < ms; i++) {
    delayMicroseconds(1000);
  }
}

le code que j'utilise est le suivant :

void setup()
{
Serial.begin(9600);

Serial.println("Hello world!"); // C'est ici que ca coince... Car ca n'affiche pas le texte dans un champ texte
}

void loop()
{

}

Il y a me semble-t-il pourtant ce dont tu as besoin. Regarde, il y a même l'émulation de la frappe de "Welle world".
Sur ce, je passe en mode horizontal car c'est 01H30 ici et grosse journée en perspective.
Tu devrais y arriver, lis le code et ça va te sauter aux yeux.

Bonjour, merci de votre aide.

Je pense que la solution est la suivante :

// http://code.rancidbacon.com/ProjectLogArduinoUSB
#include "UsbKeyboard.h"

// Define the inputs to use for buttons
#define BUTTON_MSG 10

// Use the on-board LED as an activity display
int ledPin = 13;

/**
* Configure button inputs and set up the USB connection to the host
*/
void setup()
{
  // Set up the activity display LED
  pinMode (ledPin, OUTPUT);
  digitalWrite (ledPin, HIGH);

  // Set the button pins to inputs
  pinMode (BUTTON_MSG, INPUT);

  // Enable the CPU's internal 20k pull-up resistors on the button
  // inputs so they default to a "high" state
  digitalWrite (BUTTON_MSG, HIGH);

  // Disable timer0 since it can mess with the USB timing. Note that
  // this means some functions such as delay() will no longer work.
  TIMSK0&=!(1<<TOIE0);

  // Clear interrupts while performing time-critical operations
  cli();

  // Force re-enumeration so the host will detect us
  usbDeviceDisconnect();
  delayMs(250);
  usbDeviceConnect();

  // Set interrupts again
  sei();
}


/**
* Main program loop. Scan for keypresses and send a matching keypress
* event to the host
* FIXME: currently repeats as fast as it can. Add transition detection
*/
void loop()
{
  UsbKeyboard.update();

  if (digitalRead(BUTTON_MSG) == LOW) {
    UsbKeyboard.sendKeyStroke(KEY_M);
    UsbKeyboard.sendKeyStroke(KEY_O);
    UsbKeyboard.sendKeyStroke(KEY_N);
    UsbKeyboard.sendKeyStroke(KEY_Space);
    UsbKeyboard.sendKeyStroke(KEY_M);
    UsbKeyboard.sendKeyStroke(KEY_E);
    UsbKeyboard.sendKeyStroke(KEY_S);
    UsbKeyboard.sendKeyStroke(KEY_S);
    UsbKeyboard.sendKeyStroke(KEY_A);
    UsbKeyboard.sendKeyStroke(KEY_G);
    UsbKeyboard.sendKeyStroke(KEY_E);
    UsbKeyboard.sendKeyStroke(KEY_ENTER);
    digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle status LED
  }

}


/**
* Define our own delay function so that we don't have to rely on
* operation of timer0, the interrupt used by the internal delay()
*/
void delayMs(unsigned int ms)
{
  for (int i = 0; i < ms; i++) {
    delayMicroseconds(1000);
  }
}

Reste plus qu'a trouver le fichier de l'inclusion .h et ca devrai etre bon.

Sinon, je n'ai qu'un bouton poussoir qui reste en position high ou low quand on le presse, pensez vous que ca fera l'affaire ? Si oui, est il necessaire de mettre une resistance sur la led et le BP ?

Merci encore pour votre aide :slight_smile:

http://code.google.com/p/vusb-for-arduino/downloads/detail?name=vusb-for-arduino-005.zip&can=2&q=

Pour ton inclusion, vois ce lien

Dans la section ressources, suis le lien de code chez Google et tu auras un zip contenant entre autres le fichier .h voulu, je crois.
Après, pour ton bouton, je pense que cela va t'obliger à gérer le fait qu'un changement d'état a été appliqué ou pas. Sinon tu risques d'injecter X fois ton texte.
A le lire, ton code me semble en effet bon.
Tiens nous au jus

J'ai reussi a trouver un site avec un schemas pour pouvoir mettre un bouton et y ajouter une diode avec la resistance et tout le necessaire.

Voici le site,je vous informe des que j'ai fais mon petit montage avec peut etre photo a l'appui :slight_smile: