element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum need help urgently..
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 15 replies
  • Subscribers 403 subscribers
  • Views 1387 views
  • Users 0 members are here
Related

need help urgently..

Former Member
Former Member over 11 years ago

i m making software with arduino..there is some sensor types and they have particular ids like

temp1       sensor id=1         decimal value 49(accordingto ascii code)

like this there are 8 different sensors.i hvae to '

read the serial

store in a data array

compare 1st byte against sensor id

copy rest of data from and display to serial pc

please can anybody help me in coding

please

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 11 years ago in reply to Robert Peter Oakes +1
    THANKS Peter thanks so much.. you are really very helpful person
Parents
  • mcb1
    mcb1 over 11 years ago

    Harman

    It helps if you post the code ... otherwise its like "Can you see that".

     

    use the >> and Syntax Highlighting C++ and copy the code in

    Fullscreen contentimage_182515.html Download
    <html><head><title>Jive SBS</title></head>
    <body><font face="arial,helvetica,sans-serif">
    <b>Error</b><br><font size="-1">
    An general error occurred while processing your request.
    </font></font></body></html>
    

     

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to mcb1

    thnks Mark for replying

    void setup ()

    {

    //initialise serial communication with computer

      Serial.begin(9600);

    // initialize all reading to 0:

    }

    char indata[20];

    int Serial_counter

    void loop()

    {

      //write loop that will control what we want the arduino to do with sensor readout

      Serial.write("1:23:7");

    {

      if(Serial.available()>0) //dont read unless there you know there is data

      {

    indata = Serial.read(); //read a integer

    Serial_count++;

    }

    if(indata[0]=='49')

    {

      Serial.print("temp1=");

      Serial.print1n(1:23:7);

    }

     

    dont know this is right or wrong but i tried for one sensor

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Former Member

    Harman

    Where did you get this from.?

    You have one unclosed brackets. (Proper indentation helps spot it) and you used a 1 instead of lowercase L in the Serial.println(1:23:7) statement

     

    // initialize all reading to 0:   
    char indata[20];  
    int Serial_counter  
      
    void setup ()   
    {  
     //initialise serial communication with computer  
      Serial.begin(9600);  
    }  
      
    void loop()  
    {  
      //write loop that will control what we want the arduino to do with sensor readout  
      Serial.write("1:23:7");  
      if(Serial.available()>0) //dont read unless there you know there is data  
      {  
        indata = Serial.read(); //read a integer  
        Serial_count++;  
      
        if(indata[0]=='49')  
        {  
          Serial.print("temp1=");  
          Serial.println(1:23:7);        // this should have been println as 'ln' not 'one' n  
        }
      }  
    }

     

    I presume it came up with errors.

     

    I haven't tried it.

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to mcb1

    thanks but still it shows error.i just take help from internet and try to display ..but it didnt workimage..i was doing another project but due to some circumstances they change it and i dont know much about arduino ...please help me

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Former Member

    Harman

    Don't cross post as it makes it hard to follow which answer works.

    Post the error you get when you compile it and maybe then someone can assist.

     

    Also the internet is really big ... so the link to where you copied it form might help.

     

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to mcb1

    these following error shown when i compile it..i didnt just copied all the data. i read and try to write code

     

     

     

     

    finallll:5: error: expected initializer before 'void'

    finallll:5: error: expected initializer before 'void'

    finallll.ino: In function 'void loop()':

    finallll:17: error: incompatible types in assignment of 'int' to 'char [20]'

    finallll:18: error: 'Serial_count' was not declared in this scope

    finallll:23: error: expected `)' before ':' token

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to Former Member

    Hi Harman, Im feeling like being extra helpful today so...

     

    I had a bit of time at lunch so here is a quick framework to get you started, lots of room for improvement but good enough for a beginner to follow

     

    As Mark said, not sure where your code came from but lots of errors in it

     

    the following is based on your code but added structure and capability

     

    demonstrates modular program and reasonably good structure, as I said, not much time

    // declare global variables at top so there easy to find and modify
    char indata[20] = "" ; // assign empty string so we dont get issues with unterminated strings
    int Serial_counter = 0; // you had ; missing
    const int sensorCount = 3;// do as many as needed for sensors
    int sensorVal[sensorCount]; // assumes sensor input is an integer and or converted to an integer before storing
    
    void setup () 
      {
        //initialise serial communication with computer
        Serial.begin(9600);
        
         //do other initialization like the sensors if needed
         sensorVal[0] = 10;
         sensorVal[1] = 20;
         sensorVal[2] = 30;
        // initialize all reading to 0: 
      }
    void loop()
      {
        //write loop that will control what we want the arduino to do with sensor readout
        readSensors();
        processCommand();
      }
    
    void readSensors()
    {
      //this would normally be reading from real world sensors
     for (int count = 0 ; count<sensorCount ; count++)  
          {
          // normally you would read the sensor and input to the array
          sensorVal[count]++; // increment the dummy sensor value each time it is accessed
          }
    }
    
    void processCommand()
    {
      while(Serial.available() > 0) // Don't read unless
      // now you know there is data
      {
         if(Serial_counter < 19) // One less than the size of the array, dont want memory leak
         {
           indata[Serial_counter] = Serial.read(); // Read a character
           Serial_counter++; // Increment where to write next
           indata[Serial_counter] = '\0'; // Null terminate the string
         }
      }
      // now compare the read string with a number of preset values
      // and if in range print value
      if (indata ==  "sensor1")
        { 
          printSensor(0); // 0 indexed array
        }
      else if (indata == "sensor2")
        {
          printSensor(1); // 0 indexed array
        }
      else if (indata == "sensor3")
        {
          printSensor(2); // 0 indexed array
        }
      else if (indata == "All")
        {
        for (int count = 0 ; count<sensorCount ; count++)
           {
             printSensor(count); // 0 indexed array
           }
        }
       else
        {
          Serial.println("Invalid Sensor ID");
          Serial.println(indata); // send back what we received
          Serial.println("was not found");
        }
    }
    
    // so we don't have to duplicate the print code for every sensor and waste flash memory
    void printSensor(int sensorID)
    {
        Serial.print(millis());  // asuming this will be replaced with some time value
        Serial.print("Sensor ") ;
        Serial.print(sensorID); 
        Serial.print(" =");
        Serial.println(sensorVal[sensorID]); // this would be replaced with the actual read value
    }

     

     

    Harman, hope you can now adapt for your use, adding sensor reading and time output etc etc.

     

    Mark, feel free to add what you feel will help or if I made a mistake

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to Robert Peter Oakes

    Peter

    It was 2am, and I wasn't feeling like writing someone else's code for them.

    I was going to find a tutorial since it seems the basics aren't understood, so obviously more learning is required.

     

    To me it seems that this was part of a bigger project that involved serially connected sensors, or it was an assignment.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago in reply to mcb1

    Agreed, that's why I only provided a basic framework, there is still plenty to do to get a viable program running and I needed something like this for myself anyway

     

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Robert Peter Oakes

    THANKS Peter thanks so much..image

    you are really very helpful person

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Former Member
    Former Member over 11 years ago in reply to Robert Peter Oakes

    THANKS Peter thanks so much..image

    you are really very helpful person

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube