Programming

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Karma73
 
Posts: 4
Joined: Mon Jun 20, 2022 9:25 am

Programming

Post by Karma73 »

I was wondering if someone could help and point me in the right direction if it’s possible…
I have a product that has a “Trinket” installed and I want to swap it out for the “Trinket MO” but I need to download / pull the program from the original, because I don’t have access to the original program.

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: Programming

Post by dastels »

You're out of luck I'm afraid. To move the program from a Trinket to TrinketM0 you'll need the C++ source code. At the very least it will need to be recompiled for the M0, and might require rework depending on how AVR specific the code is.

Dave

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Programming

Post by adafruit_support_bill »

If it is one of the original ATTiny-85-based trinkets, that is not possible to do. In theory with the appropriate tools, you could extract the binary program data from the Flash memory. But the processor architectures of the ATTiny-85 and the ATSAMD-21 (M0) are vastly different so the binary code from one will not execute on the other.

User avatar
Karma73
 
Posts: 4
Joined: Mon Jun 20, 2022 9:25 am

Re: Programming

Post by Karma73 »

Is there a tutorial or something I could read up on, if possible then to basically clone what’s on a Trinket and put on a new Trinket, not the Trinket MO?
I’m working on a controller for my saltwater aquarium and the company I bought them from is not the greatest to deal with and they said they are now discounted. I sent it in for warranty and they said they fixed it, but apparently they didn’t. My other controller is working properly, so I was wondering if I could extract the program from that one and download it to a new Trinket board.

User avatar
Karma73
 
Posts: 4
Joined: Mon Jun 20, 2022 9:25 am

Re: Programming

Post by Karma73 »

Board
Board
64CBE0C4-F4F0-4F38-8BC5-BC3250144896.jpeg (120.85 KiB) Viewed 251 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Programming

Post by adafruit_support_bill »


User avatar
Karma73
 
Posts: 4
Joined: Mon Jun 20, 2022 9:25 am

Re: Programming

Post by Karma73 »

Okay, Thanks
Once I get time, I’m going to attempt this.

User avatar
Terry5
 
Posts: 6
Joined: Mon Apr 09, 2018 6:06 pm

Re: Programming

Post by Terry5 »

I need help programming my Trinket 3.3 & 5v, I would like to and serial-print or available. My other question similar to what is listed below in this forum; Can I use code from trinket on trinket Mo for real-time monitoring?

Code: Select all

[code]
#include<avr/power.h>
/* Trinket/Gemma compatible IR read sketch
This sketch/program uses an Adafruit Trinket or Gemma
ATTiny85 based mini microcontroller and a PNA4602 or TSOP38238 to
read an IR code and perform a function.  In this
test program, tones are generated to a piezo speaker
but you can use codes to trigger any function you wish.
Based on Adafruit tutorial http://learn.adafruit.com/ir-sensor/using-an-ir-sensor
and http://learn.adafruit.com/trinket-gemma-mini-theramin-music-maker
*/
 
// We need to use the 'raw' pin reading methods because timing is very important here 
// and the digitalRead() procedure is slower!
#define IRpin_PIN  PINB // ATTiny85 had Port B pins
#define ledpin     4    // Piezo speaker on Trinket/Gemma Pin GPIO #4/D4
#define IRpin      3    // IR sensor - TSOP38238 on Pin GPIO #3 / D3
#define IRpin      2    // IR sensor - TSOP38238 on Pin GPIO #2 / D2
#define SPEAKERPIN 1    // Piezo speaker on Trinket/Gemma Pin GPIO #1/D1
#define SPEAKERPIN 0    // Piezo speaker on Trinket/Gemma Pin GPIO #0/D0
 
#define MAXPULSE    1000  // the maximum pulse we'll listen for - 1000 milliseconds 
#define NUMPULSES    3  // max IR pulse pairs to sample
#define RESOLUTION     2  // // time between IR measurements
 
// we will store up to 20 pulse pairs (this is -a lot-, reduce if needed)
uint16_t pulses[10][2];   // pair is high and low pulse
uint16_t currentpulse = 0; // index for pulses we're storing
uint32_t irCode = 0;
int incomingByte = 0; // for incoming serial data

void setup() 
{
  if (F_CPU==16000000)clock_prescale_set(clock_div_1);
  {
  Serial.begin(9600);
}
  pinMode(ledpin, OUTPUT); // Output tones on Trinket/Gemma pin D4
  pinMode(IRpin, INPUT);       // Listen to IR receiver on Trinket/Gemma pin D3
  pinMode(IRpin, INPUT);       // Listen to IR receiver on Trinket/Gemma pin D2
  pinMode(SPEAKERPIN, OUTPUT); // Output tones on Trinket/Gemma pin D1
  pinMode(SPEAKERPIN, OUTPUT); // Output tones on Trinket/Gemma pin D0
 int incomingByte = 0; // for incoming serial data
 }
 
void loop() {
  
  irCode=listenForIR(); // Wait for an IR Code
 
  // Process the pulses to get our code
  for (int i = 0; i < 32; i++) {
    irCode=irCode<<1;
    if((pulses[i][0] * RESOLUTION)>0&&(pulses[i][0] * RESOLUTION)<500) {
      irCode|=0; 
    } else {
      irCode|=1;
    }
  }
  if(irCode==1500,1000,600)  {      // "1" 6JPBI2SmprSHr6NaWbePaGT6QUu6C5Y3KzhebSXCOjKRrjjeDVRKBaklUnDReAma
    beep(SPEAKERPIN,85960,7991000); }  // Make a 400 Hz beep
  else if (irCode==380,340) { // "2", BF2E8A71A6CC7
    beep(SPEAKERPIN,579570,67530); }  // Make a 500 Hz beep
  else if (irCode==238,200.3,200,70,68,67) { // "3", 6JPBI2SmprSHr6NaWbePaGT6QUu6C5Y3KzhebSXCOjKRrjjeDVRKBaklUnDReAma
    beep(SPEAKERPIN,250000,31250000); } // Make a 600 Hz beep
  else if (irCode==150,130,150,125,100) { // "4", BF2E8A71A6CC7
         (SPEAKERPIN,31250000,250000);  // Make a 700 Hz beep
         
  }
   // send data only when you receive data: {
    // read the incoming byte:
    {
int incomingByte = Serial.read();
    }
    // say what you got:
}    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  
} // end loop
 
 
uint16_t listenForIR() {  // IR receive code
  currentpulse = 0;
  while (1) {
   unsigned int highpulse, lowpulse;  // temporary storage timing
   highpulse = lowpulse = 0; // start out with no pulse length 
  
   while (IRpin_PIN & _BV(IRpin)) { // got a high pulse
      highpulse++; 
      delayMicroseconds(RESOLUTION);
      if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse; 
      }
   }
   pulses[currentpulse][0] = highpulse;
 
   while (! (IRpin_PIN & _BV(IRpin))) { // got a low pulse
      lowpulse++; 
      delayMicroseconds(RESOLUTION);
      if (((lowpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
        return currentpulse; 
      }
   }
   pulses[currentpulse][1] = lowpulse;
   currentpulse++;
  }
}
 
// Generate a tone on speakerPin - Trinket/Gemma/ATTiny85 compatible
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{   // http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
          int x;   
          long delayAmount = (long)(1000000/frequencyInHertz);
          long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
          for (x=0;x<loopTime;x++)   
          {  
              digitalWrite(speakerPin,HIGH);
              delayMicroseconds(22000000);
              digitalWrite(speakerPin,LOW);
              delayMicroseconds(1000);
          }  
}
[/code]

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Programming

Post by adafruit_support_bill »

@Terry5 - This thread is about extracting binary data from a Trinket. Please start a new thread for your question:

posting.php?mode=post&f=52

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”