Shop OBEX P1 Docs P2 Docs Learn Events
Need help converting arduino program to BS2 — Parallax Forums

Need help converting arduino program to BS2

ScurgeScurge Posts: 7
edited 2008-11-19 17:02 in BASIC Stamp
It's a simple program, and I know I should be able to do this myself but I don't know anything about arduino other than it looks alot like C++ (i have a little C++ coding experience from a gen ed college course). I haven't had any luck figuring out exactly what the program does by I2C and I don't have an arduino to scope the signal to copy it (or even compile and run it). I gather that it sends the byte array to one wire, but I'm not sure what exactly is being sent. What the program does is reset an unknown type of counter chip on a cleaner cartage (so I can refill and reuse it).

the arduino code is:

#include <Wire.h>

#define CG (B1010000)
boolean resetSuccess = false;
int isReset = 13;

int byteArray [noparse][[/noparse]]= {01, 01, 01, 60, 60, 60, 60, 60, 60, 8, 8, 8, 33, 33, 33, 255};

void setup()
{ 
  pinMode(isReset, OUTPUT);
  digitalWrite(isReset, LOW);

  Wire.begin();        // join i2c bus (address optional for master)
}

void loop()
{
  if (resetSuccess) 
  {
    delay (2000);      // our work is done - pause for a while 
    resetSuccess = false;
  } else {
    resetCartridge();
    resetSuccess = verifyCartridge();
    digitalWrite(isReset, resetSuccess);
  }
}

void resetCartridge()
{
  for (int i=3; i < sizeof(byteArray)/2; i++)
  {
    Wire.beginTransmission(CG);
    Wire.send(i);
    Wire.send(byteArray{i});      'the "{}"'s here would be replaced by "[noparse][[/noparse]]" but it made it italics on this forum post
    Wire.endTransmission();
    delay(4);
  }
}

void movePointerTo(int deviceAddr, int memoryAddr)
{
  Wire.beginTransmission(deviceAddr);
  Wire.send(memoryAddr);
  Wire.endTransmission();
}

boolean verifyCartridge()
{
  boolean success = true;
  movePointerTo(CG, 3);
  Wire.requestFrom(CG, 3);
  while (Wire.available())
  {
    if (Wire.receive() == 60 && success == true)
    { 
      // looking good so far
    } else {
      success = false;
    }
  }
  return success;
}




the entire instructions on the arduino model can be found here --> www.instructables.com/id/CatGenie_Resetting_a_SaniSolution_Cartridge/ , if there is any thing you want to know about what's being done.

While we're on this topic, is there anyway to assign a list of numbers to an array at one time? Like, in this program it is:
int byteArray [noparse][[/noparse]]= {01, 01, 01, 60, 60, 60, 60, 60, 60, 8, 8, 8, 33, 33, 33, 255};


the only thing I've found in the help files assigns an array through a for loop, one address at a time.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-19 00:47
    Your program is short enough and the Arduino is simple enough that you should be able to figure out what the program does. Download an Arduino manual for the details. I don't think you'll get someone here to do the work for you without paying them as a consultant for their time.

    You can store a constant array in EEPROM using the DATA statement, then read the contents using the READ statement. Look at the chapters in the Parallax Stamp Basic Manual on the DATA and READ statements for details
  • ScurgeScurge Posts: 7
    edited 2008-11-19 04:32
    Well, I've sat a while with the online reference manual for arduino with little progress. I downloaded the compiler and fiddled with that for a while, with no luck. I'm having trouble conceptualizing what the for loop is doing in the resetCartrige function.

    And, I'm not asking someone to "do the work for me," and quite frankly that suggestion rubs me the wrong way. I'm asking for a little insight from someone who has adruino knowledge (or see's something I'm missing) to save me hours of searching around for code tutorials on a platform I don't even have. I'm definitely not asking someone to re-write the code for me. I have a BS2 and can code it myself. And if I knew people were expecting payment for their help or advice on these forums, I don't know that I'd have come here at all in the 1st place. I'm not looking for a flame war, but that kinda ticks me off.

    I appreciate the help on the array. but the disposition of the rest of the post is not a great way to help your forum community (to which you are obviously a large contributor) grow.

    Post Edited (Scurge) : 11/19/2008 4:40:01 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-19 14:19
    Now, now, no need to get testy.

    The BS2 would use the "DATA" statement for your "byteArray" above.

    Sometimes, all you need is a Rosetta Stone.

    The attached should be close to what you want.· Things it does not cover -- wire.available, is it REALLY an I2C connection (in which case you might need a Bs2p), when does "setup()" get called, stuf like that.

    But it does illustrate using "DATA" statements (and the READ statement) to implement the array stuff.


    Post Edited (allanlane5) : 11/19/2008 2:24:58 PM GMT
  • ScurgeScurge Posts: 7
    edited 2008-11-19 16:03
    Thank you very much.· That code explains alot.· I'm sure·I can get it to work now.· When·I get done with the program working and the circuit set up, I'll post directions for anyone else who has a CatGenie and is tired of paying for refill cartriges.·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-19 17:02
    And Scurge, please remember in the future that everyone is here to help you, but this is a Parallax support forum and it is unlikely that there will be a lot of members on here familiar with Arduino code. What we can help you with is BASIC Stamp code in this forum, so it is up to you to provide us with as much information about the source code as possible. If you don’t know anything about Arduino and post the code then I can see where Mike was coming from. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.