I started using Visual Studio 2022 with Visual Micro, Arduino 1.6/1.8 as my new Arduino IDE, because I needed some extra features, that the original Arduino IDE does not provide.
To plot a graph, I am using the breakpoint command {#Plot.windowName.graphName variable} to print out the graph for my variable x with x = sin(2i), i being incremented by 0.01 every cycle by a for loop.
Here is my code:
double x;
void setup() {
Serial.begin(115200);
Serial.println("Hello, World!");
}
void loop() {
float i;
for (i = 0; i < 1000; i=i+0.01) {
x = sin(2*i);
Serial.println(x);
delay(50);
}
}
Here is a picture of the breakpoint command:
The graph this outputs looks jagged and has cyclically occurring lags every 1.5 second.
Where might this originate from?
Is it the Visual Micro software, the speed/noisiness of the serial connection (bad cable, etc.) or the Arduino Uno being overloaded by that?
I already tried changing the data rates as recommended in the answer of visualmicro.
Unfortunately it is not about the data rate itself.
The Serial Debugger in Visual Micro throttles the data coming from the sketch to prevent the PC becoming overloaded with Serial data.
If you enable the vMicro > Debugger > Full Speed (no throttle), this should speed up the data coming in.
Also the interval the chart refreshes at can be changed from the controls above it, in this scenario "At rate of incoming data" would be best suited.
Related
I found some answers that didn't solve my issue for STM32F302.
I configured the debug run as follows, to printf() in the SWV ITM Data Console:
IMG-Debug_Config
I implemented the _write function as follows:
int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
ITM_SendChar((*ptr++));
}
return len;
}
And tried to setup the sys clock for "Asynchronous Trace" and "Serial Wire", none worked and I keep getting the same output (SWV Graph does not work either):
IMG-SWV_Output
Any suggestion about this issue? I just want to debug the variable to make sure I'm getting the correct measurement.
PS. Just a brief of my project: An ADC for a light sensor. I need to generate a graph from a laser sample measurement. Make this measurement with the STM32 and a photodiode, finish the measurement and send the .csv or .txt from USB to a computer to analyse the data.
I found what my problem was:
My "Core Clock (MHz)", in the debug settings, was wrong and that's why my SWV was not working properly
If no SWV data - you need to connect the SWO pin to ST-LINKV2. The SWV data transmission is on the SWO pin. On my STM32F3DISCOVERY, the SB10 was not soldered, SB10 connecting the PB3 SWO pin to the T_SWO debugger net. After soldering SB10 SWV work perfectly.
for a prototype we need to have a hardware switch (e.g., a momentary pushbutton) trigger the taking of a screenshot on a PC and save it to file. Writing some windows software to take a screenshot and save it is trivial, the slightly trickier part is how to get an electrical signal (we can choose the voltage, and provide power as necessary) to the software. We absolutely want to keep this simple (i.e., no labview or anything) and reliable as possible. I see small module boxes such as this
https://labjack.com/products/u3?gclid=EAIaIQobChMI-MXkjcbB2gIVxVYNCh3C6AODEAQYAiABEgK_OvD_BwE
available, but are there even simpler solutions? I'm thinking of (but haven't taken the time to test) possibly a parallel-port-to-USB converter (which would be similar to the more common RS232-to-USB converter but may allow detection of individual high/lows(just a guess, never worked with a parallel driver from windows)), or something like that. Just querying for ideas before I spend time buying things and testing. Thanks!
This can be easily done with an Arduino Leonardo, Micro, and Due module. This page has an example very similar to your project:
// use this option for OSX:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
// char ctrlKey = KEY_LEFT_CTRL;
void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);
}
I'm working on a room visualization project, similar to this (taken from this video):
Im using LeddarVu8 from leddartech (see image below), arduino uno (with rs485shield):
I've also used the code provided from leddartech of simple16channel (no lcd):
#include "C:\Program Files (x86)\Arduino\libraries\Leddar.h"
/*
Simple Leddar(TM) Example - Without LCD
Language: Arduino
This program lists the detections read on the serial port of the Arduino.
Can be used with Arduino IDE's Serial Monitor.
Shields used:
* RS-485 Shield
Created 01 Jun. 2015
by Pier-Olivier Hamel
This example code is in the public domain.
*/
Leddar16 Leddar1(115200,1);
//Baudrate = 115200
//Modbus slave ID = 01
void setup()
{
//Initialize Leddar
Leddar1.init();
}
void loop()
{
char result = Leddar1.getDetections();
if (result >= 0)
{
for (int i = 0; i < Leddar1.NbDet; i++)
{
Serial.print("Segment: ");
Serial.print(Leddar1.Detections[i].Segment);
Serial.print(" Distance: ");
Serial.print(Leddar1.Detections[i].Distance);
Serial.print("\n");
}
}
else
{
Serial.print("Error: ");
Serial.print((int)result);
Serial.print("\n");
}
delay(50);
}
(from https://support.leddartech.com/downloads/files/89-leddarsdk3-2-0-pi2-tar-gz)
The problem is that serial monitor of the arduino only outputs a series of ?????. Why is that?
The problem is that serial monitor of the arduino only outputs a series of ?????. Why is that?
Because you have connected the TX of the LIDAR to the TX of the Arduino. The Serial Monitor window "listens" to the Arduino TX pin (via USB), so the Serial Monitor is actually listening to the LIDAR. The LIDAR serial is running at 115200, but your Serial Monitor is probably set to 9600. When the baud rates don't match, you'll get garbage characters.
Also notice that you have two serial TX pins connected to each other. This will also corrupt the characters if the Arduino and the LIDAR both try to transmit at the same time.
You may be able to connect the LIDAR RX to the Arduino TX, and the LIDAR TX to the Arduino RX. This would allow you to see the Leddar library commands on the Serial Monitor window. It would also cause all Serial prints to go to the LIDAR (and the PC). This might be ok if the Leddar command packets have a special format. This would allow the Leddar to ignore your debug prints, because they would not formatted correctly.
In that configuration, you would have to disconnect Arduino pin 0 to upload new sketches over USB. Some people put a switch in that wire to make it easy to disconnect.
I have recently been trying to pneumatically actuate a cylinder using a 12 V double solenoid and an Arduino Uno. The solenoid works when tested without code and wiring, however when I try to actuate the cylinder using code, nothing happens. I have a feeling that the way in which I wired everything to the breadboard may be incorrect, so I was wondering if anyone had any tips or good schematics by which I could wire it all together.
The materials I am using are two PNP transistors, two resistors, two diodes, and then the actual solenoid and similar hardware. My code is just a simple LED blink code which can be used to send signals to the solenoids, so I do not believe that is the issue. However, I have attached it underneath just in case.
int solenoid1 = 4;
int solenoid2 = 5;
void setup() {
// put your setup code here, to run once:
pinMode(solenoid1, OUTPUT);
pinMode(solenoid2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(solenoid1, HIGH);
delay(1000);
digitalWrite(solenoid1, LOW);
digitalWrite(solenoid2, HIGH);
delay(1000);
digitalWrite(solenoid2, LOW);
}
Arduino digital pin puts 5V when HIGH. So your 12V solenoid do not get enough voltage to run. You have to use relay and additional 12V power supply to run your solenoid with Arduino.
The code which I have written is not running when the Arduino gets plugged in
How can you see this?
A solenoid certainly cannot be controlled by 5V * 20mA from an Arduino pin. Further requirements depend on the solenoid you want to use. (Current consumption, free-wheeling diode already integrated?)
What is the standard method to read values on an Arduino from a C application?
I have an accelerometer and a few poentiometers which I would like to bind to Cocoa controls, an NSSlider for example.
My arduino is currently connected to: /dev/cu.usbmodem26431 and I can read the values printed by the AnalogReadSerial code sample in the Serial Monitor.
How do I read from /dev/cu.usbmodem26431 ?
Cocoa Serial (Edit)
Three methods of interfacing with Objective C are presented here
http://arduino.cc/playground/Interfacing/Cocoa
Arduino Serial
If you know how to establish a Serial/USB connection then you can send the values as either string or binary to the Arduino.
In the setup() method on the Arduino you establish as Serial connection like this.
nb: using 115200 baud/speed for this example
Serial.begin(115200);
In the loop() method on the Arduino you can read data from the c application. here is a full Arduino example including how to send data back to the c application using Serial.print()
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(115200); // opens serial port, sets data rate to 115200 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
Source http://arduino.cc/en/Serial/read
The example above is very crude, you can use Serial.available() to see how much data is waiting to be read.
For strings you might want to use a \n line terminator or other type of terminator as an indicator for the end of a packet (to know when it has been fully received).
It is a good idea to design your own header and check sum to ensure data integrity but I don't bother with check sums for simple unimportant projects.
As an example, gps systems often send sentences when in string/text mode. If you look up the Arduino library called tinyGPS, you will see one way to read an entire sentence into different variables within an Arduino program.
This is an NMEA GPS sentence, do not use the same header in your projects, instead, design your own. This is just an example of how you might transmit multiple values (int, string, float etc) to an Arduino
$GPBWC,081837,,,,,,T,,M,,N,*13
http://aprs.gids.nl/nmea/