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
    About the element14 Community
  • 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 Help, my Processing code is restarting my Arduino code
  • 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
  • State Verified Answer
  • Replies 35 replies
  • Answers 1 answer
  • Subscribers 420 subscribers
  • Views 4111 views
  • Users 0 members are here
Related

Help, my Processing code is restarting my Arduino code

kjhart0133
kjhart0133 over 12 years ago

Hello all,

I'm developing some Arduino code using XBees to sense environmental data at a remote location. My Arduino code is working great and I'm now ready to upload my remotely acquired data to my computer so that I can parse the data and send it via an SMS message to my smart phone. This way I can monitor my remote location from anywhere.

I'm using a chunk of code I got from the "Getting Started with Processing" book by Reas and Fry. I am able to get the Arduino/XBee data into my computer this way, but I have a problem/issue:

The Arduino code loops continually, but each time I start the Processing Code, it restarts (resets?) the Arduino code. The Arduino code starts over from the beginning going through setup and then into the loop. I have no idea why this is happening. Here is the Processing code I'm using:

// Based on Example 11-07 from "Getting Started with Processing"

// by Reas & Fry. O'Reilly / Make 2010

// This sketch, as modified by kjh, reads data from an Arduino, stores it in an array

// then saves the data to a file on disk.

 

import processing.serial.*;

 

Serial port;                     // Create object from Serial class

int asize = 8;                 // define size of data array

byte[] val = new byte[asize];    // Data received from the serial port

                                 // representing the setting of the pot

int i = 0;                       // array index

int x;                           // scratch value

float y;

 

void setup() {

  //size(440, 220);

  // IMPORTANT NOTE:

  // The first serial port retrieved by Serial.list()

  // should be your Arduino. If not, uncomment the next

  // line by deleting the // before it. Run the sketch

  // again to see a list of serial ports. Then, change

  // the 0 in between [ and ] to the number of the port

  // that your Arduino is connected to.

  println(Serial.list());

  String arduinoPort = Serial.list()[2];

  port = new Serial(this, arduinoPort, 9600);

}

 

void draw() {

    if (port.available() > 0) {        // If data is available,

      x = port.read();        // read it and store it in val

      val[i] = byte(x);

      y =  float(x);

      //println(y);

      println(val[i]);

      //val = map(val, 0, 255, 0, height);  // Convert the value

      i++;

    }

    if (i > asize-1){

      saveBytes("arduino_data.dat", val);

      println("Data written.");

      exit();

    }

}

My Arduino code does not read data from the computer or Processing, it only sends data to Processing. The Arduino code is quite long and involved using a fair amount of XBee interface code so I didn't include it here. But, as I said, it is running fine except for being restarted each time I run the Processing code.  I'm using an Mega Arduino board connected to my PC via the USB cable. 

I greatly appreciate any assistance on this.

Thanks,

Kevin H.

  • Sign in to reply
  • Cancel

Top Replies

  • kjhart0133
    kjhart0133 over 12 years ago in reply to mcb1 +1
    Success!! After trying a number of different things without solving the problem, I finally cut the jumper on the reset line between the USART and the Mega chip and this did the trick. These forums are…
  • kjhart0133
    kjhart0133 over 12 years ago in reply to kjhart0133 +1
    To solve the problem of now not being able to upload sketches, I soldered a wire to each of the reset line solder pads and wired an SPST switch across the two solder pads. This works perfectly (so far…
  • kjhart0133
    kjhart0133 over 12 years ago in reply to Robert Peter Oakes +1
    Peter, That's great info about the ports. I'm learning a lot in this thread. Here's a block diagram of my system that shows all the components. I run Processing code in the PC that uploads data from the…
Parents
  • kjhart0133
    0 kjhart0133 over 12 years ago

    OK, I'll respond to several points:

     

    1.  I am not sharing the Serial/USB port between the Processing code on the PC and the XBees.  If you look closely on the diagram you'll see that XBee #1 is connected to SERIAL 1 on the Mega.  The PC is connected to the Mega via the usual Serial/USB interface.  I'm sorry it wasn't clear on the diagram; I should have made the little Serial 1 box bigger.  Anyway, this is why I chose the Mega, because it had additional serial ports.  And it all works well now.

     

    2.  As to the question of why do I care about repeated resets.  Technically I shouldn't; the resets don't bother anything, more a nuisance.  On the other hand it's not really good programming.  Somewhere down the road I might want to add code that might be adversely affected by repeated resets -- I don't know, just thinking out loud.  Also, I will want to poll my remote sensors repeatedly to monitor conditions in the remote location.

     

    3.  I really like the suggestion to use Processing directly to run XBee #1 and eliminate the need for the Mega altogether.  Equally interesting is the suggestion to use GMS or a modem to eliminate need for the PC.  I'm going to have to give these two ideas some thought and some research.  I've never heard of GMS so I'm off to Google it.  Maybe I'll code up a simple test to try them out.  Either of these two plans would significantly simplify my system.

     

    4.  Uploading my Mega code.  Hmmm.  First, I can't see how to upload files.  There doesn't seem to be a button to do that.  Second,  I'm embarrassed to show my code.  I'm not a programmer so my code is not what anyone would call pretty.  Still, if someone really wants to see it, let me know and send me a hint on how to upload it.  I can just send it as an Arduino .ino file and that will preserve all the colors, etc., when you open it in the Arduino IDE.

     

    Thanks again for great ideas and helpful suggestions.

     

    Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • kjhart0133
    0 kjhart0133 over 12 years ago

    OK, I'll respond to several points:

     

    1.  I am not sharing the Serial/USB port between the Processing code on the PC and the XBees.  If you look closely on the diagram you'll see that XBee #1 is connected to SERIAL 1 on the Mega.  The PC is connected to the Mega via the usual Serial/USB interface.  I'm sorry it wasn't clear on the diagram; I should have made the little Serial 1 box bigger.  Anyway, this is why I chose the Mega, because it had additional serial ports.  And it all works well now.

     

    2.  As to the question of why do I care about repeated resets.  Technically I shouldn't; the resets don't bother anything, more a nuisance.  On the other hand it's not really good programming.  Somewhere down the road I might want to add code that might be adversely affected by repeated resets -- I don't know, just thinking out loud.  Also, I will want to poll my remote sensors repeatedly to monitor conditions in the remote location.

     

    3.  I really like the suggestion to use Processing directly to run XBee #1 and eliminate the need for the Mega altogether.  Equally interesting is the suggestion to use GMS or a modem to eliminate need for the PC.  I'm going to have to give these two ideas some thought and some research.  I've never heard of GMS so I'm off to Google it.  Maybe I'll code up a simple test to try them out.  Either of these two plans would significantly simplify my system.

     

    4.  Uploading my Mega code.  Hmmm.  First, I can't see how to upload files.  There doesn't seem to be a button to do that.  Second,  I'm embarrassed to show my code.  I'm not a programmer so my code is not what anyone would call pretty.  Still, if someone really wants to see it, let me know and send me a hint on how to upload it.  I can just send it as an Arduino .ino file and that will preserve all the colors, etc., when you open it in the Arduino IDE.

     

    Thanks again for great ideas and helpful suggestions.

     

    Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • ipv1
    0 ipv1 over 12 years ago in reply to kjhart0133

    Wanna share code? Social Coding? want people to contribute? Share and help?

    The answer http://www.github.com

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 12 years ago in reply to kjhart0133

    I've been programming for over 35 years and some of mine still looks ugly, what matters in your position is "does it work "and "is it bug free", the rest will come with experience, and were not here to criticize, were hear to help you and I can guarantee any seasoned programmer will have seen worse.

     

    Sorry about the serial confusion, I did not look that closely at the diagram and assumed you where plugging the xBee via a shield onto the Mega and therefor using the standard connections. My Bad image

     

    GMS, I think that may be a typo, and possibly should be GSM as mcb1 stated, it is a standard Cell phone network system, the only issue there (Not technical) is needing an carrier account ( Phone Number) for each node with a GSM module. you could get away with just the primary node and have it relay to the rest and its worth considering. if the nodes are spread out enough to justify it.

     

    Alternate Suggestion

    As an alternate approach if your open to suggestions, my home network of nodes use simple radios to talk to each other (NRF24L01) in a mesh, a master node (Mega or similar) has an ENC28J60 to provide access from the internet.  http://www.google.ca/search?q=enc28j60

     

    then NETIO (Available for Android and Iphone) is used to provide remote monitoring from anywhere that has internet access which if using a cell phone with a data plan is pretty much everywhere  http://netio.davideickhoff.de/ this in inexpensive and works very well,

     

    A friend and buddy developer in England uses the above setup to remotely monitor his home in Spain from the UK, very reliable and inexpensive to setup,

     

    In your setup, if the actual monitored nodes are close together (Bluetooth range so less than 30 feet or so) so you do not walk around with the PC to get into range of them this would also work as the Radios have more range than Bluetooth and will also relay to nodes not in range. supports hundreds of nodes if you want to.

     

    This mirrors what I think your trying to achieve, certainly functionally, and at a lower cost. You could always add instant messaging to the master controller for alerts etc. My friend and I have been working on this for a while and he has a great blog describing it all  http://www.scargill.net/tag/netio-comes-to-the-rescue-home-control/

     

    either way you want to take this, i'm happy to continue assisting as best I can. I hope you are finding the feedback useful

     

    If there are enough people interested I will see if I can post the code we use and any other technical details on the forum, (I will bounce it of my friend first as he has written quite a bit of the code). It supports PWM, several temp sensor types, other Analog inputs, relay outputs, schedules, and we are adding features all the time.

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 12 years ago in reply to Robert Peter Oakes

    Here is a recent update regarding the home control im working on with my friend  http://www.scargill.net/2014/02/

     

    Enjoy

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to kjhart0133

    Kevin

    here is a link to one version ... sorry we refer to them as GSM, but overseas they use GRPS.

    http://www.seeedstudio.com/depot/gprs-shield-v20-p-1379.html?cPath=132_134

    wiki http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0

     

    As peter eluded you do need a SIM, however depending on your providers you may be able to get a data sim, or the equivalent which means a minimal monthly cost.

    From your block diagram there is only one connection to worry about.

     

    The other option to consider is adding an Ethernet connection and eliminating the PC.

     

    Anyway, now your resetting issue is resolved, you can continue testing and ironing out any small issues.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube