But nothing is printing on the Monitor of Arduino IDE ...
What's wrong with this source :
#include <Bridge.h> #include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
Bridge.begin(); // Initialize Bridge
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Test 1");
// set the data rate for the SoftwareSerial port
mySerial.begin(1200);
mySerial.println("Hello, world");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
You better use an Arduino Leonardo for the Dragino Yun Shield.
Pin 0 (RX) and pin 1 (TX) are used to upload a sketch and for the serial monitor. But when the Dragino Yun shield is attached, those pins are used for the Bridge.
I found on this : "A SoftwareSerial library allows for serial communication on any of the Yún's digital pins. Pins 0 and 1 should be avoided as they are used by the Bridge library."
So I use the pin 10 for my input but it don't work ...
What did you connect to pin 10 and 11 ? I hope some kind of usb-serial-5V-compatible-adapter.
Have a look at this code:
Bridge.begin(); // Initialize Bridge
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Test 1");
The Bridge is initialized (it uses pin 0 and 1), and after that the Bridge is overruled when you take over those pins with "Serial.begin(9600);".
In the loop, you also use Serial functions.
The Bridge really needs those pins 0 and 1. That means you can't use 'Serial' anymore, only the software mySerial.
That is why a Leonardo is so much easier.
With the Leonardo, the uploading of a sketch, and use of serial monitor is done directly via the USB without the use of pin 0 and 1.
Can you please tell what you have connected to pin 10 and 11 ? Some connect it to RS-232, that could damage the Arduino. If you have connected pin 10 and 11 to a usb-serial-5V-compatible-adapter(converter), then you have an extra serial port on the computer, which can be used by the serial monitor (or any other serial terminal program).
I mentioned "adapter". I ment a small module, a converter. An adapter adapts things. I know, a "power supply" can also be a "adapter", but I ment a converter.
Peter_n:
You better use an Arduino Leonardo for the Dragino Yun Shield.
Pin 0 (RX) and pin 1 (TX) are used to upload a sketch and for the serial monitor. But when the Dragino Yun shield is attached, those pins are used for the Bridge.
@sonnyyu : I try to make it work without buying a new card ... if it's not possible I will buy it ... but if it's possible with this, it's better for me
Elmout:
I try to make it work without buying a new card ... if it's not possible I will buy it ... but if it's possible with this, it's better for me
It's possible with an Uno, but you will get USB serial communications, or Yun Shield communications, you can't have both. This is because the Serial interface (pins 0 and 1) are used for both the USB communications, and the Yun Shield communications. Therefore, if you want to use the Yun Shield, you must disable the Uno's USB interface and never use the Serial object in your sketch.
The Leonardo uses Serial to talk to the USB interface, and doesn't use pins 0 and 1 to do this, that's why it's a better fit. The Leonardo uses Serial1 to talk to pins 0 and 1, which go to the Yun Shield, and therefore you with the Leonardo you can use the USB serial interface and the shield at the same time.
That is a very small circuit to receive serial data. It should be possible to read that with SoftwareSerial.
The TX of the SoftwareSerial is not used yet, you can use that to send messages to the computer, using a usb-serial converter : http://store.arduino.cc/product/A000059
There are many of those usb-serial converters. If you buy one from Ebay, it might have a fake chip.
If you can connect to the Dragino Yun Shield via Ethernet or wifi with the Arduino IDE, you could try the Console at port 6571.
I always use an Leonardo board and always use the serial monitor via usb for messages, because I can't always connect with the Arduino IDE via Ethernet or wifi.
Peter_n:
That is a very small circuit to receive serial data. It should be possible to read that with SoftwareSerial.
Why would the size of the circuit have anything to do with the ability to use SoftwareSerial?
SoftwareSerial is best applicable for situations that use high baud rates, and low volume of data. From the schematic, we can't tell anything about the data volume, but it does mention 1200 baud. The software serial library has this to say about baud rates:
**Be circumspect about using 300 and 1200 baud though. The interrupt handler at these rate becomes so lengthy that timer tick interrupts can be starved, causing millis() to stop working during receives.
How the Dragino Yun Shield and Uno are powered has not to do with the baudrate.
I wrote about an 'adapter', but I ment a 'converter'. Like this one : http://www.arduino.cc/en/Main/USBSerial
The TX pin of the SoftwareSerial could be used with such a converter to show messages on the computer.
What kind of battery do you want to use ? Not a small 9V battery I hope.
Powering the Dragino Yun shield with USB 5V... is that possible ? I think the Dragino Yun shield uses VIN to create power for the wifi/linux/OpenWRT module.
The 9V 'chargeur' is okay.
The 9V battery is not okay. The Dragino Yun shield requires some current (100-300mA ?). The 9V battery might last only half an hour.
I can work on this project this weekend so I try to use 9V battery for the test.
And it's work !! I receive the info of my power consomation !
So I continu my project and send the datas to my Synology Nas to make the storage in mySQL batabase.
Now my code is this :
#include <Console.h>
#include <AltSoftSerial.h>
#include <HttpClient.h>
char incomingByte; // a variable to read incoming Console data into
AltSoftSerial altSerial;
void setup() {
Bridge.begin(); // Initialize Bridge
Console.begin(); // Initialize Console
// Wait for the Console port to connect
while (!Console);
pinMode(8, INPUT);
altSerial.begin(1200);
}
void loop() {
// On récupère la trame téléinfo
char CaractereRecu ='\0';
String Trame;
while(CaractereRecu != 0x02) // boucle jusqu'a "Start Text 002" début de la trame
{
if (altSerial.available()) {
CaractereRecu = altSerial.read() & 0x7F;
}
}
while(CaractereRecu != 0x03) // || !trame_ok ) // Tant qu'on est pas arrivé à "EndText 003" Fin de trame ou que la trame est incomplète
{
if (altSerial.available()) {
CaractereRecu = altSerial.read() & 0x7F;
Trame+=CaractereRecu;
}
}
Console.println(Trame);
// fin récupération trame téléinfo
// envoi sur le nas les données pour insertion en base de donées
// Initialize the client library
HttpClient client;
Console.println("Envoi de la requête HTTP pour stockage!");
client.get("http://www.christellelacour.fr/teleinfo_edf/insertionData.php?trame"+Trame);
Console.println("Traitement du retour !");
String retourHttpGet;
while (client.available()) {
char c = client.read();
retourHttpGet += c;
}
retourHttpGet.trim();
Console.println(retourHttpGet);
}
But now when I open the monitor I obtain this message : Connection closed by foreign host
Elmout:
I obtain this message : Connection closed by foreign host
It means that you contacted a server out there somewhere on the Internet, but it didn't properly respond to your request, it just closed the connection (hung up the phone on you.) It's most likely that the server didn't like something in your request, and is actively ignoring you.
Before you make the client.get() call, I would suggest making a Console.println() of the entire string you are going to use for the request. Does it look properly formatted? Might you be missing an equal sign between the parameter name trame and the value Trame? If you manually type that exact string into your web browser's address bar, does it work or give a more meaningful error message? Does it ask you for any additional information, like a username or password?