93Views8Replies

Author Options:

How to communication between arduino and computer? Answered

I am working on Fleet management and this with my project
There are three possible states for the device which we need to implement (Off, Running, Configuration, Factory Settings)
There should be a button to change the device status (only one button please).
If the device is already off, pressing this button should bring the device in running mode.
If the device is on, pressing this button for 5 seconds should bring the device in configuration mode
If the device is in configuration mode, pressing the button for 5 seconds should restart the device, and pressing the button 3 times should set the variables to default values.
If the device is on, pressing the button for 10 seconds turn of the device
When the device is in configuration mode, we should be able to plug the device with a computer using USB. The device should start sending it's internal APN code with a specific sequence e.g. TR<APN>RT as soon as it sends this code to the computer, it should wait for response from the computer.
The computer can sends back the code TR<APN>RT or no response.
When the device receives TR<APN>RT, it should match the IMMI it sent and the IMMI it received. If both matched, then it should wait for settings:
The computer will send data as TR<varname:value>RT where varname is e.g. APN, USERNAME, PASSWORD, URL, POLL_INTERVAL etc. the value after first : is the the value of the variable.
The device should save these values to SD or it's internal memory immediately.
Now press the button for 5 seconds, the device should restart and straight away enter into running mode. Now the device should connect to server using and sends GPS location and speed every interval set by the POLL_INTERVAL variable.
Let's achieve this first, I'll add more functionality once we're done with this.
Thanks,

Tags:Fleet

Discussions

0
None
steveastrouk

Best Answer 3 years ago

Go ahead, when you get stuck with your project, we can offer advice. Communication between a PC and an Arduino is very simple, with a serial stack interface.

0
None
rickharris

2 years ago

OK after 25 years of supporting and writing software Your question worries me in several ways.

ALL projects containing software go belly up for the same reason, Because the original problem wasn't specified well enough, because of this the client didn't know what they really wanted (in detail), the developer didn't know what they were trying to solve and continual change threw the project timescale and budget totally out of the window. and the project manager had no chance of getting things right or on time or in budget.


Remember these wise words because I formed a company in 1989 to resolve these problems, they are so common the company traded for 20 years an only stopped due to ill health and old age.

QUALITY software is software that does exactly what the client needs.

This of course assumes that those needs have been adequately identified in a form that allows the developer to break the problem down and develop solutions to each part.

The fact you have asked the question suggests you haven't specified well enough, or you don't have the skill set required (and should hire in the skills unless this is an educational project and you ARE the skills)

In my experience:

1. you need to have a Client Requirement specification (CRS) saying everything the system MUST do. This includes any hardware issues, personnel issues and GUI requirements. Once fixed and agreed by the client this CRS will NOT be changed UNLESS a changes are costed and Project time extended to account for the change.

2. you must respond with a User requirement specification (URS) which is your working document and reflects how everything in the Client Requirement specification will be solved and should break the software system into functional modules.

3. You need to create your software functional modules to the URS each module should be documented WHEN it is written. It should be tested against the URS.

4. Your finish software when fully assembled WILL work as specified because that's how you created it AND how you tested each part. Therefore the development will be controlled, no surprises, be on time and in budget.

You may feel the instructable below are too basic for you BUT they were created for students, Unless your already doing these things your project will not succeed.

Trust me I specified, developed, wrote and managed many many projects worth £millions.

I created a software quality assurance system for my company with the aim of being able to create software that was on time, in budget and fully functional at the time of installation.

https://www.instructables.com/id/Starting-a-micropr...

https://www.instructables.com/id/Starting-a-micropr...

0
None
Downunder35m

2 years ago

Where is the code, where is the exact problem in the code?
We might be able to help to fix some problems in existing code but we won't do the programming for you.
If you agreed to take the project than it was your fault as you should only accept project you are confident you can handle them.
So provide the code, we have a goodlook and maybe find room for improvement.

But from what I gather so far you want the glory for "your" project while in fact someone else did it for you ;)

0
None
SulemanCDownunder35m

Answer 2 years ago

i am not asking you to do my work i am just looking for the event or a path how would i do this .. i am confuse how to enter some values in program variable without using serial monitor or arduino ide.

0
None
Downunder35mSulemanC

Answer 2 years ago

If you want to get serial data to the Arduino than the usual standard protocols apply - they are quite well documented too.
So once all is correct you can use a simple terminal program for the serial communication, dedicated programs, python, VB - whatever suits your needs.
Might be best to start with some simple code example from the libraries and Arduino websites...
And as said without some actual code here we can't give any advise on how to fix a problem with the code.

0
None
SulemanCDownunder35m

Answer 2 years ago

what i am doing in this program is try to call four function as i define when i click ,doubleclick,hold button and long hold button i want if i press long button my arduino device turn on ans when i double click button configurattion setting appears and i would manually enter some value in it,same as for two other restart and power off the arduino.

here the code i am working on:

#include<Button.h>

#define buttonpin 2

#define ledPin1 13

boolean ledVal1 = false;

String APN;

char A=0;

void setup()

{

Serial.begin(9600);

pinMode(buttonpin,INPUT);

digitalWrite(buttonpin,HIGH);

pinMode(ledPin1, OUTPUT);

digitalWrite(ledPin1, ledVal1);

}

void loop()

{

int b=checkbutton();

if(b==1) clickevent();

if(b==2) doubleclickevent();

if(b==3) holdevent();

if(b==4) longholdevent();

deviceon();

//device_configuration();

// restart_device();

// turnoff_device();

}

void clickevent()

{

//ledVal1 = !ledVal1;

//digitalWrite(ledPin1, ledVal1);

Serial.println("TURN DEVICE ON");

//device_configuration();

if (Serial.available() > 0)

{ // is a character available?

A = Serial.read(); // get the character

if (A != '\n') {

APN += A;

}

else

{

Serial.print("Enter APN = ");

Serial.println(APN);

String APN="";

Serial.println("");

delay(2000);

}

}

}

void doubleclickevent()

{

//device_configuration();

}

void holdevent()

{

//restart_device();

}

void longholdevent()

{

//turnoff_device();

}

// Button timing variables

int debounce = 20; // ms debounce period to prevent flickering when pressing or releasing the button

int DCgap = 250; // max ms between clicks for a double click event

int holdTime = 5000; // ms hold period: how long to wait for press+hold event

int longHoldTime = 7000; // ms long hold period: how long to wait for press+hold event

// Other button variables

boolean buttonVal = HIGH; // value read from button

boolean buttonLast = HIGH; // buffered value of the button's previous state

boolean DCwaiting = false; // whether we're waiting for a double click (down)

boolean DConUp = false; // whether to register a double click on next release, or whether to wait and click

boolean singleOK = true; // whether it's OK to do a single click

long downTime = -1; // time the button was pressed down

long upTime = -1; // time the button was released

boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered

boolean waitForUp = false; // when held, whether to wait for the up event

boolean holdEventPast = false; // whether or not the hold event happened already

boolean longHoldEventPast = false;// whether or not the long hold event happened already

int checkbutton()

{

int event = 0;

// Read the state of the button

buttonVal = digitalRead(buttonpin);

// Button pressed down

if (buttonVal == LOW && buttonLast == HIGH && (millis() - upTime) > debounce)

{

downTime = millis();

ignoreUp = false;

waitForUp = false;

singleOK = true;

holdEventPast = false;

longHoldEventPast = false;

if ((millis()-upTime) < DCgap && DConUp == false && DCwaiting == true) DConUp = true;

else DConUp = false;

DCwaiting = false;

}

// Button released

else if (buttonVal == HIGH && buttonLast == LOW && (millis() - downTime) > debounce)

{

if (not ignoreUp)

{

upTime = millis();

if (DConUp == false) DCwaiting = true;

else

{

event = 2;

DConUp = false;

DCwaiting = false;

singleOK = false;

}

}

}

// Test for normal click event: DCgap expired

if ( buttonVal == HIGH && (millis()-upTime) >= DCgap && DCwaiting == true && DConUp == false && singleOK == true)

{

event = 1;

DCwaiting = false;

}

// Test for hold

if (buttonVal == LOW && (millis() - downTime) >= holdTime)

{

// Trigger "normal" hold

if (not holdEventPast)

{

event = 3;

waitForUp = true;

ignoreUp = true;

DConUp = false;

DCwaiting = false;

//downTime = millis();

holdEventPast = true;

}

// Trigger "long" hold

if ((millis() - downTime) >= longHoldTime)

{

if (not longHoldEventPast)

{

event = 4;

longHoldEventPast = true;

}

}

}

buttonLast = buttonVal;

return event;

}

// four steps we which we need to do

void deviceon()

{

//Serial.println("DEVICE IS TURING ON");

}

void device_configuration()

{

// if (Serial.available() > 0)

// { // is a character available?

// A = Serial.read(); // get the character

//

// if (A != '\n') {

//

// APN += A;

// }

// else

// {

// Serial.print("Enter APN = ");

// Serial.println(APN);

// String APN="";

// Serial.println("");

// delay(2000);

// }

// }

}

void restart_device()

{

//Serial.print("RESTARTING THE DEVICE..");

//delay(1000);

}

void turnoff_device()

{

//Serial.print("TURN OFF DEVICE");

//delay(1000);

}

0
None
SulemanCDownunder35m

Answer 2 years ago

yes i strictly need to follow that steps .so kindly if you help in completing my code or provide some good suggestion i will really appreciate it.

0
None
Downunder35mSulemanC

Answer 2 years ago

Just use the example and configure the pins as you need them.
If you want to trigger events like starting a new code section you do so as well, just instead of the digital write function.