Good evening,
my project is to create a desktop application.
This application will allow me to communicate from the PC to an stm32 microcontroller via the usb port.
I use the class: QSerialPort available on Qt
I want to know the number of USB port connected on my PC.
Here is my code:
#include <QCoreApplication>
#include <QDebug>
#include <QSerialPort>
#include <QSerialPortInfo>
Int main (int argc, char * argv [])
{
QCoreApplication a (argc, argv);
QDebug () << "Number of serial ports:" << QSerialPortInfo :: availablePorts (). Count ();
Return 0;
}
So I plugged my microcontroller stm32f4, an external hard drive with a usb cable ...
My problem is this: When I run the program under Qt there is no compilation problem but the result of the debug shows me the following line: "Number of serial ports: 0" Usb ports connected.
Following the activation of bluetooth or the insertion of a 3g key there is detection of these ports, but the others remain undetected.
I didn't understand where the mistake comes from !!
Qt only has native support for USB Serial ports. (eg: COM/TTY)
If you want to know low level details (eg: physical port number) of the USB port the STM is connected to, you have to use platform specific code.
Libusb can help you with that.
Related
I am using teensy 3.2 to program its K20 series microcontroller Mk20DX256
I have written a simple UART code to transmit a character 'U' from teensy to PC and see it on Docklight.I have disabled interrupt and DMA
I have searched through web and found out that Teensy acts as Serial port only when Serial type code is running
Otherwise it acts as USB Port
I uploaded 'hello' example from arduino to board and chose Usb serial port
This prints hello on serial monitor.the device is detected in COM PORT in hardware manager
But when i try to program my hex file generated from keil into the board
The Com port option disappers from Port in hardware manager
It means my code is not serial type
#include "MK20D7.h"
void UARTPutChar(char);
int main()
{
SIM->SCGC4=1UL<<10; //Clock Enable Uart0
SIM->SCGC5 =1UL<<12;//Enable GPIO PORT A clock
UART0->C2=0X00; //Disable UART
PORTD->PCR[7]= 0x00000300; //Port pin declare as UART0TX
UART0->BDH=0x01; //
UART0->BDL=0xD4;
UART0->C1=0X00;
UART0->C3=0X00;
UART0->S2=0X20;
UART0->S1=0X40;
UART0->C2=0X08; //Enable UART0
while(1)
{
UARTPutChar('U');
}
}
void UARTPutChar(char ch)
{
if(UART0->S1 == 0X40)
{
UART0->D=ch;
}
}
Anyone please guide what i am doing wrong.
If you compile for Teensy with Arduino, the build system will link in the Teensyduino core library which contains a working USB stack. Specifically, per default it will configure it as a CDC device (virtual serial port).
If you compile with Keil, I assume that you need to tell the IDE that you want to link in a USB stack and how you want it configured
Currently our tool uses QTCPSocket->ConnectToHost to connect to our TCP server, which works.
The problem arises when some of our machines are bridging two networks, across two entirely different IP ranges (10.x.x.x, 172.x.x.x). When you try to connect to a device on the 172.x.x.x network, it appears to be trying to connect via the 10.x network interface, and then times out and fails to connect. On windows, if you disable the network port for the 10.x network and reload the tool, it correctly uses the 172.x network interface and connects. I can see no way with QTCPSocket to force it to connect using a specific interface, or am I missing something? It seems like the 10.x network is getting priority somehow and we always try to use that when trying to establish an outgoing connection, which is not what we want.
Ideally, the user would be able to select what network interface they want to use to make the connection, whether its the 10.x or 172.x network.
This is using QT 5.15.0.
You can select the outgoing interface to use by calling bind() with your interfaces address first. This will select your outgoing address to use.
See the documentation for the bind function:
For TCP sockets, this function may be used to specify which interface to use for an outgoing connection, which is useful in case of multiple network interfaces.
I threw together a very simple demo for you:
Its all running locally. This is the servers main.cpp:
#include <QCoreApplication>
#include <QTcpServer>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTcpServer serv;
QObject::connect(&serv, &QTcpServer::newConnection, [](){
qDebug() << "New connection!";
});
qDebug() << serv.listen(QHostAddress("192.168.x.y"), 1337);
return a.exec();
}
And this is the clients main.cpp:
#include <QCoreApplication>
#include <QDebug>
#include <QTcpSocket>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTcpSocket s;
qDebug() << s.bind(QHostAddress("127.0.0.1"));
s.connectToHost(QHostAddress("192.168.x.y"), 1337);
return a.exec();
}
By calling bind we tell the client to send packets using the local interface, but as the server only listens to my wifi interface 192.168.x.y the connection will fail. If you now change the following line:
qDebug() << s.bind(QHostAddress("127.0.0.1"));
as such:
qDebug() << s.bind(QHostAddress("192.168.x.y"));
You will see that the server will recieve the connection, as we explicitly selected this interface to send from.
However, the operating system should select the correct interface for you (meaning in the demo: by not calling bind you should get a connection). If that does not happen you have a different issue.
To get a list of all available interfaces you can use QNetworkInterface::allInterfaces() which will grant you access to everything might you need to know.
I'm trying to use the Adafruit Fona Mini GSM together with the Nucleo L073RZ. There exists a library for the GSM module, but it's for arduino. I've setup the board manager url to make use of the link in this repository: https://github.com/stm32duino/Arduino_Core_STM32/blob/master/README.md to add support for the MCU I'm using.
It's not possible to use SoftwareSerial together with this MCU it seems like. The library disappears when the card is selected. The GSM library supports HardwareSerial by uncommenting some lines though, which I've done. Unfortunately the MCU is unable to communicate with the GSM module.
Tera Term image
This is how everything is connected.
Hardware image
In case it's not apparent by the picture, this is how the GSM module connects to the MCU.
Vio connects to 5V
GND connects to GND
RX connects to TX/D1
TX connects to RX/D0
This is the only code modification I've made in the FONATest example, just to use hardware serial instead of software serial.
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three
lines
// and uncomment the HardwareSerial line
//#include <SoftwareSerial.h>
//SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
//SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
HardwareSerial *fonaSerial = &Serial1;
so I got my Arduino Uno today. For a porject I want to be able to control some relays on my Arduino via Wifi (via Blynk app). For this I want to use the ESP8266-01 as a Wifi shield.
I used this tutorial: https://create.arduino.cc/projecthub/nolan-mathews/connect-to-blynk-using-esp8266-as-arduino-uno-wifi-shield-m1-46a453
Only difference is I'm using Win10. Here is what I got:
Arduino Uno R3
Arduino IDE 1.8.1
included all Blynk/ESP libraries and installed ESP8266 as board (generic)
uploaded empty sketch to the Arduino
Connections to Between Arduino/ESP as follows . http://www.teomaragakis.com/hardware/electronics/how-to-connect-an-esp8266-to-an-arduino-uno/ (I know about to 3.3V to 5V issue but seems to work so far)
Okay, first problem is that I couldnt flash the Firmware of the ESP (got it from Sunfounder) as said in the Tutorial. Downloaded the latest firmware and flashed it with ESP8266Flasher.
Other Problem that is when I try to compile the code from the first tutorial, I always get error :
C:\Users\Chris\Documents\Arduino\libraries\Blynk\examples\Boards_WiFi\ESP8266_Shield\ESP8266_Shield.ino:5:21: fatal error: ESP8266.h: No such file or directory
As said I have installed all libraries. Cant really think of things to do anymore. Any help would be much appreciated. Best regards from Berlin, Chris.
To close the code I try to upload to the board (both Arduino Board or generic ESP8266 does not work)
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266.h>
#include <BlynkSimpleShieldEsp8266.h>
// Set ESP8266 Serial object
#define EspSerial Serial
ESP8266 wifi(EspSerial);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "???";
void setup()
{
Serial.begin(115200); // Set console baud rate
delay(10);
EspSerial.begin(115200); // Set ESP8266 baud rate
delay(10);
Blynk.begin(auth, wifi, "???",
"???");
}
void loop()
{
Blynk.run();
}
The ??? I switched for my token and data ofc.
Try changing this
#include <ESP8266.h>
to this
#include <ESP8266_Lib.h>
The file was renamed in this commit.
I am in the middle of my project, and I am now trying to make a connection between two XBees, exactly like in this the YouTube video XBee Basics - Lesson 2 - Simple Chat Program Between Two XBees in AT Mode. I setup the network in the X-CTU first, and now I am trying to connect the XBees with Arduinos.
In the Arduino programming software, the side of the router works fine - I can see in the serial monitor that it's sending the "Hello World" messages, but on the side of the coordinator, it does not receive any massages.
Platform:
Arduino IDE version 1.03-1.05.
XBee Series 2
Arduino Uno
I suppose that the "Hello word" message on the router side is due to a Serial.print() instruction that you have included for debbuging purpose.
Arduino Uno like my Arduino nano have only one serial port (the usb) and if you use it for power purpose or debugging or transmitting data to the PC it is considered busy and anything connected to the pin 0 and 1 will be ignored.
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip. it is from arduino site).
You need to create a software serial port with the library SoftwareSerial (is it included in Arduino IDE since version 1.0)
to call the library and define the software serial port you can use this piece of code
#include <SoftwareSerial.h>
uint8_t rxxbee = 2;
uint8_t txxbee = 3;
SoftwareSerial Serial_xbee(rxxbee,txxbee);
Rember to connect the RX of the arduino to TX of the XBee and viceversa.