A machine for the transformation of thermal energy into mechanical work or electrical energy, the machine comprising: i) a first (20, 20') and a second (22, 22') coaxial and cylindrical block side by side, separated by a cylindrical partition of insulating material, said cylindrical blocks (20, 22') and said insulating partition being provided with axial cavity housing a rotary member provided with a first and a second cam, each placed in correspondence of each of said cylindrical blocks (20, 22) and having the two cam profiles such as to generate a coordinated movement of the pistons housed in said cylindrical blocks; ii) a series of cylindrical working chambers (34, 34') in each of said cylinder blocks (20, 22), each of said working chambers (34, 34') being open at the bottom towards said axial cavity of said cylindrical blocks (20, 22) and being provided with a single-acting piston (36, 36') provided with a contrast spring (38, 38') and acting on an idle roller (40, 40') in contact with said cams (30, 32) of said rotary member, thereby defining a first series of working chambers in said first cylindrical block, a second series of working chambers in said second cylindrical block, a first series of pistons acting on a corresponding first series of rollers in contact with said first cam, and a second series of pistons acting on a corresponding second series of rollers in contact with said second cam; iii) a plurality of communication channels between said first and second series of working chambers (34, 34'), each of said channels putting in communication a chamber of said first cylindrical block with a corresponding chamber of said second cylindrical block through said insulating partition, each of said chambers (34, 34') being also provided with communication channels (48, 48') with an external reservoir for a fluid working in said chambers, and a plurality of distribution valves of said fluid between said communication channels and said working chambers; said first cylindrical block being operatively exposed to a heat source adapted to heat said working fluid in said first working chambers, while said second cylindrical block is thermally isolated from said first cylindrical block and placed in contact with a lower temperature heat source whereby it is cooled, such that in said first and second working chambers said working fluid carries out thermodynamic cycles of compression and expansion as a result of the motion of said pistons (36, 36') and the corresponding rotation of said cams (30, 32) and of said rotary shaft. i) a first (20, 20') and a second (22, 22') coaxial and cylindrical block side by side, separated by a cylindrical partition of insulating material, said cylindrical blocks (20, 22') and said insulating partition being provided with axial cavity housing a rotary member provided with a first and a second cam, each placed in correspondence of each of said cylindrical blocks (20, 22) and having the two cam profiles such as to generate a coordinated movement of the pistons housed in said cylindrical blocks; ii) a series of cylindrical working chambers (34, 34') in each of said cylinder blocks (20, 22), each of said working chambers (34, 34') being open at the bottom towards said axial cavity of said cylindrical blocks (20, 22) and being provided with a single-acting piston (36, 36') provided with a contrast spring (38, 38') and acting on an idle roller (40, 40') in contact with said cams (30, 32) of said rotary member, thereby defining a first series of working chambers in said first cylindrical block, a second series of working chambers in said second cylindrical block, a first series of pistons acting on a corresponding first series of rollers in contact with said first cam, and a second series of pistons acting on a corresponding second series of rollers in contact with said second cam; iii) a plurality of communication channels between said first and second series of working chambers (34, 34'), each of said channels putting in communication a chamber of said first cylindrical block with a corresponding chamber of said second cylindrical block through said insulating partition, each of said chambers (34, 34') being also provided with communication channels (48, 48') with an external reservoir for a fluid working in said chambers, and a plurality of distribution valves of said fluid between said communication channels and said working chambers;