Support forum for the Geiger Counter.
Post Reply
Posts: 1
Joined: Wed Apr 25, 2012 3:47 am


Post by ronym »

I don't know why I did not start here!? I've been posting this question on C++ and Arduino forums and have had not kind responses.
I am trying to create a Geiger counter that posts a Tweet using an Arduino and ethernet shield. (eventually to use WiFi shield)

The MightyOhm geiger counter has an awesome serial port that supplies all the details needed. A SerialEvent sketch reads and can println the String with no issue.

I use the Tweet library for Arduino
That also works perfectly alone to post information.

The issue: I am trying to create a 'String.toCharArray' with the serial data from the geiger counter that can be ( posted to twitter on a set interval.
I believe it's the 'String.toCharArray' where my problem is. it just won't put the String into anything I can use?
also, there may be a way to use a buffer like this?

Code: Select all

char buffer[140] = {0};
any help would be great!

all the code:

Code: Select all

#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>

// from
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>

// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 1, 66 };

// Your Token to Tweet (get it from
Twitter twitter("token goes here");

//from SerialEvent
const String g("geiger");
String inputString = "g";         // a string to hold incoming data
  char charArray[80];
  String:g:toCharArray(charArray, 80);
  boolean stringComplete = false;  // whether the string is complete

void setup()
  Ethernet.begin(mac, ip);
  // Ethernet.begin(mac);
//  String::toCharArray()  //testing
  inputString.reserve(200); //(200
//  inputString.toCharArray(g, 80);
  if (
  Serial.println("connecting ...");
//  if ( {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
    } else {
      Serial.print("failed : code ");
  } else {
    Serial.println("connection failed.");

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    // clear the string:
    inputString = "";
    stringComplete = false;

  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char); 
    // add it to the inputString:
    inputString += inChar;
 delay (10000);
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;

Post Reply