import processing.serial.*;
String COM5;
Serial myPort;
String val;
void setup() {
String portName=COM5;
myPort= new Serial(this,portName,9600);
}
void draw() {
if(myPort.available()>0){
val=myPort.readStringUntil('\n');
}
println(val);
}
This is my code, I have copied from a website. when I try running it is showing
Error opening serial port null:null not permitted
I am badly in need of answer to go forward in my thermal imaging project.
You never give COM5 a value, so it's null. Then you pass that into the Serial() constructor. The Serial() constructor doesn't know what do do with a null value, so you get the error.
Please take a step back and read a tutorial on using the Serial library. The official documentation contains example code that uses the Serial() constructor correctly.
COM5 hasn't got a value as a String.
Try this in Processing:
import processing.serial.*;
Serial myPort;
String val;
void setup() {
myPort= new Serial(this, "COM5", 9600);
}
void draw() {
if (myPort.available()>0) {
val=myPort.readStringUntil('\n');
}
println(val);
}
Double check your Arduino appears as COM5 in Device Manager and you don't have Arduino's Serial Monitor open when you run the Processing sketch.
Related
I have basically connected a speaker to Arduino uno board. I just need help with the code. I have used the TMRpcm library to make it easier. However, it seems to be giving me an error everytime. here is the code below.
include "SD.h"
define SD_ChipSelectPin 10
include "TMRpcm.h"
include "SPI.h"
TMRpcm audio;
void setup(){
audio.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
audio.setVolume(10);
audio.play("Spring_In_My_Step_-_Silent_Partner_Mp3Converter_ne.wav");
}
void loop()
{
}
any and all help is appreciated
thank you!
I am trying to post an object to my parse.com app from my arduino yun and it needs to post a new object every second. So far I have been able to post every 10 seconds but I cannot seem to get the arduino to post any faster than that. I tried looking into the parse library but don't see what would be slowing it down. I am using the parse library given in the guide at https://www.parse.com/docs/arduino/guide.
here is the code I have so far.
#include <Parse.h>
#include <Bridge.h>
#include <arduino.h>
ParseObjectCreate create;
void setup() {
Serial.begin(9600);
parseInit();
}
void loop() {
parseFunc(24); // just send 24 everytime for testing
}
void parseInit()
{
Bridge.begin();
while (!Serial); // wait for a serial connection
Parse.begin("**********", "***********"); //my parse keys
create.setClassName("Temperature");
}
void parseFunc(float tempC)
{
create.add("temperature", tempC);
ParseResponse response = create.send();
response.close();
}
You are probably being rate limited by Parse. The code executed in loop() is executed as quickly as the micro controller can execute it - which is very fast. As a result, you are trying to write to Parse many many more times than once a second. Try putting a call to delay() after parseFunc(24). Something like:
parseFunc(24);
delay(1000); //delay is in milliseconds
Let me know if it works!
I am trying to do simulation in OMNeT++ and I have used Veins and SUMO as well in the simulation, but I have got this error:
Model error: TraCI Server reported error executing command 0xcc("View
'#0' is not known")..
I am using the header file TraCICommandInterface.h and in that using the below mentioned class
class GuiView {
public:
GuiView(TraCICommandInterface* traci, std::string viewId) : traci(traci), viewId(viewId) {
connection = &traci->connection;
}
void setScheme(std::string name);
void setZoom(double zoom);
void setBoundary(Coord p1, Coord p2);
void takeScreenshot(std::string filename = "");
protected:
TraCICommandInterface* traci;
TraCIConnection* connection;
std::string viewId;
};
GuiView guiView(std::string viewId) {
return GuiView(this, viewId);
}
I am trying to use the takeScreenshot() function but in order to do so first I am creating an object of this class using GuiView guiView(std::string viewId).
So my question is what is viewId?
The viewId refers to which SUMO window to take a screenshot of.
For example, this screenshot
shows five views. Visible in the window titles are their names: here,
they are called View #0 to View #4.
In a project, we try to set up a communication network between three ATtinys, where the first must receive messages from the other two. Those other two tinys are connected to two different pins of the first tiny. The first tiny must then receive two strings from the other tinys, one from each, and send it to an Arduino. For the communication we used SoftwareSerial. We managed to receive and send the input from one tiny, but not from both of them, because we could not find a way to read the input from only one specific pin at a time.
This is the code we used:
#include <SoftwareSerial.h>
const int rx=4;
const int rx2=1;
const int tx=3;
const int tx2=3;
SoftwareSerial mySerial(rx,tx);
SoftwareSerial mySerial2(rx2,tx2);
void setup()
{
pinMode(rx,INPUT);
pinMode(rx2,INPUT);
pinMode(tx,OUTPUT);
mySerial.begin(9600);
mySerial2.begin(9600);
}
void loop()
{
mySerial.listen();
if (mySerial.isListening()) {
mySerial.println("Port One is listening!");
mySerial.println(mySerial.read());
}
else{
mySerial.println("Port One is not listening!");
}
mySerial2.listen();
if (mySerial2.isListening()) {
mySerial2.println("Port Two is listening!");
mySerial2.println(mySerial2.read());
}
else{
mySerial2.println("Port Two is not listening!");
}
delay(500);
}
The code above worked without the part after mySerial2.listen();. Maybe the listen-function of SoftwareSerial does not work on the tinys, but if that is the case, is there another way to listen to a specific input pin?
Or do you have any advice what to do?
I am trying to detect iBeacons with a specific UUID and Major. The didRangeBeaconsInRegion is being called but the Beacon collection it returns has 0 entries.
The below is my code (abridged a bit)
private static final String BEACON_UUID = "F8AD3E82-0D91-4D9B-B5C7-7324744B2026";
private static final int BEACON_MAJOR = 36582;
#Override
public void onIBeaconServiceConnect() {
iBeaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
if (iBeacons.size() > 0) {
IBeacon thisBeacon = iBeacons.iterator().next();
}
}
});
try {
iBeaconManager.startRangingBeaconsInRegion(new Region("myUniqueID", BEACON_UUID, BEACON_MAJOR ,null));
} catch (RemoteException e) {
e.printStackTrace();
}
}
I am assuming I am doing my binding correctly as the didRangeBeaconsInRegion(..) is being called successfully.
I have used RadiusNetwork's own application to detected the beacons and that works fine and I can see them all so it is not seem to be an issue with Bluetooth on my device
A couple of tips:
Double check that your BEACON_UUID and BEACON_MAJOR are correct for the beacon that is transmitting. For testing, try setting both of these to null temporarily until you get it working, then you can set them back to the values you have.
It is normal for the iBeacons.size() to be zero sometimes if a beacon did not happen to be detected in a given cycle. But it should not always be of size zero. I'm not sure how you are testing, but try adding a Log.d(TAG, "Number of beacons detected: "+iBeacons.size()); and let it run to see if you ever get a non-zero number.
I suggest to check the uuid , major and minor values of your beacons and make them match with the region u want.
didRangeBeaconsInRegion should return an array af beacons.
You can use the "beecon" app to update easily the values.
Hope this can help you.
Regards.