Category Archives: snippet

Auto eject on Ultimaker 1

Here’s my g-code that pushes the stretchy bracelet off from building platform:
G1 X130 ; little bit to the right so that the fan hits the object
G1 Y195 ; Brings the bed all the way forward – so the ram is behind the part
G1 Z0.2 ; Lift the nozzle slightly so it doesn’t scrape along the bed during the ramming movement
G1 Y0 F6000 ; Sends the bed moving backwards, print impacts ram and is pushed off front of bed onto paper chute

Pin interrupts on Atmega 168 + 328 (Arduino)

From http://arduino.cc/forum/index.php?topic=80928.0

From http://arduino.cc/forum/index.php?topic=80928.0

/*
* Theory: all IO pins on Atmega168 are covered by Pin Change Interrupts.
* The PCINT corresponding to the pin must be enabled and masked, and
* an ISR routine provided. Since PCINTs are per port, not per pin, the ISR
* must use some logic to actually implement a per-pin interrupt service.
*/

/* Pin to interrupt map:
* D0-D7 = PCINT 16-23 = PCIR2 = PD = PCIE2 = pcmsk2
* D8-D13 = PCINT 0-5 = PCIR0 = PB = PCIE0 = pcmsk0
* A0-A5 (D14-D19) = PCINT 8-13 = PCIR1 = PC = PCIE1 = pcmsk1
*/

Setup:

PCMSK2 |= (1<<PCINT23);
PCICR |= (1 << PCIE2);
PCMSK0 |= (1<<PCINT0);
PCICR |= (1 << PCIE0);
ISR(PCINT2_vect)




ISR(PCINT0_vect)
{
code here
}

MultiWii + Mongoose + Tricopter

If you’re using MultiWii at Mongoose-board you might wonder how to connect motors to pins.

Pinouts for tricopter:

Yaw Servo: MultiWii pin=3 = PD3 => Mongoose-pin:3
Front Left: MW=11 = PB3 => Mongoose-pin: spi-header (MOSI)
Front Right: MW=10 = PB2 => Mongoose-pin: 10
Rear: MW=9 = PB1 => Mongoose-pin: 9
RX ppm sum: mw=2 = PD2 (soldered straight to atmega328p)

See: http://www.fuzzydrone.org/2012/01/connecting-motors-and-radio-receiver-to.html

OpenSCAD 2D object that can be exported to DXF

// basic example of OpenSCAD that makes a plate that has holes in it
// you can export this to DXF because it makes 2D projection

module test()
{
// difference = first “object” is cut out with the rest of the objects
difference()
{
// union = all shapes inside union becomes one
// in this case this is the first object
union()
{
cylinder(r=30, h=3, center=true);
cube(size = [100,30,1], center = true);
}

// ok, let’s then punctuate the cylinder+cube combo with holes

for ( i = [0:10] )
{
rotate([0,0,36*i]) // rotate the “world”

translate([25,0,0]) // move away from the center
{
cylinder(r=2, h=5, center=true); // punch a hole
}
}

}
}

projection(cut=true) test();

Arduino Due performance on sin()

Tested running 100.000 sin() calls and it took 2594 milliseconds. That means you make call sin() at 38.55kHz. If you want to make 44.1kHz sound in real-time there’s no way you can use the sin() method.

Here’s the code I used

void SpeedTest()
{
float f = 1.23;

Serial.println(millis());

for (uint32_t i=0; i<10000; i++)
{
f=sin(f);
f=sin(f);
f=sin(f);
f=sin(f);
f=sin(f);

f=sin(f);
f=sin(f);
f=sin(f);
f=sin(f);
f=sin(f);

}

Serial.println(millis());

Serial.println(f);

}